{"id":13226,"library":"get-amd-module-type","title":"AMD Module Type Detector","description":"The `get-amd-module-type` package, currently at version 6.0.2, is a utility for statically analyzing JavaScript code to determine the specific pattern of an Asynchronous Module Definition (AMD) module. It supports analysis from file paths, raw source code strings, or Abstract Syntax Tree (AST) nodes, returning one of several predefined AMD module types such as 'named', 'deps', 'rem' (CommonJS wrapper), 'factory', 'nodeps' (object literal), or 'driver' (requirejs-style `require`). The package maintains a steady release cadence, primarily updating dependencies and aligning with Node.js LTS cycles; for instance, version 6.0.0 introduced a breaking change by dropping support for Node.js versions prior to 18. This library is crucial for tools performing code transformation, linting, or dependency analysis in environments that still utilize AMD module formats.","status":"active","version":"6.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/dependents/node-get-amd-module-type","tags":["javascript","module","type","amd","factory","form"],"install":[{"cmd":"npm install get-amd-module-type","lang":"bash","label":"npm"},{"cmd":"yarn add get-amd-module-type","lang":"bash","label":"yarn"},{"cmd":"pnpm add get-amd-module-type","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is primarily designed for CommonJS (`require`) environments. While Node.js >=18 supports ESM, direct `import` for the default export might require manual CommonJS wrapping or bundler configuration.","wrong":"import getType from 'get-amd-module-type';","symbol":"getType","correct":"const getType = require('get-amd-module-type');"},{"note":"`sync` is a method property of the `getType` function, not a named export. Ensure you call it from the main `getType` export.","wrong":"import { sync } from 'get-amd-module-type';","symbol":"getType.sync","correct":"const getType = require('get-amd-module-type');\nconst type = getType.sync('path/to/file.js');"},{"note":"`fromSource` is a method property of the `getType` function, not a named export. It allows direct analysis of module source strings.","wrong":"import { fromSource } from 'get-amd-module-type';","symbol":"getType.fromSource","correct":"const getType = require('get-amd-module-type');\nconst type = getType.fromSource('define([\\'dep\\'], function(){});');"}],"quickstart":{"code":"const getType = require('get-amd-module-type');\nconst path = require('path');\nconst fs = require('fs');\n\n// Example file content (replace with actual file system interaction in a real app)\nconst exampleFilePath = path.join(__dirname, 'example-amd-module.js');\nfs.writeFileSync(exampleFilePath, \"define('myModule', ['dep1', 'dep2'], function(d1, d2) { return {}; });\");\n\nconsole.log('--- Asynchronous File Analysis ---');\ngetType(exampleFilePath, (error, type) => {\n  if (error) {\n    console.error('Async Error:', error.message);\n    return;\n  }\n  console.log(`Async type for '${exampleFilePath}': ${type}`); // Expected: named\n});\n\nconsole.log('\\n--- Synchronous File Analysis ---');\ntry {\n  const syncType = getType.sync(exampleFilePath);\n  console.log(`Sync type for '${exampleFilePath}': ${syncType}`); // Expected: named\n} catch (error) {\n  console.error('Sync Error:', error.message);\n}\n\nconsole.log('\\n--- From Source String Analysis ---');\nconst sourceCode = \"define(function(require){ return {}; });\";\nconst sourceType = getType.fromSource(sourceCode);\nconsole.log(`Type from source ('${sourceCode.substring(0, 20)}...'): ${sourceType}`); // Expected: factory\n\n// Clean up example file\nfs.unlinkSync(exampleFilePath);","lang":"javascript","description":"Demonstrates asynchronous and synchronous file analysis, as well as direct source code string analysis using the `get-amd-module-type` package."},"warnings":[{"fix":"Upgrade your Node.js runtime to version 18 or higher. If unable to upgrade Node.js, pin `get-amd-module-type` to a compatible version (e.g., `npm install get-amd-module-type@5`).","message":"Version 6.0.0 of `get-amd-module-type` dropped support for Node.js versions older than 18. Applications running on Node.js < 18 must either remain on an older major version (e.g., v5.x) or upgrade their Node.js runtime.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"Upgrade your Node.js runtime to version 14 or higher (for v5.x) or 18 or higher (for v6.x). If unable to upgrade Node.js, pin `get-amd-module-type` to a compatible version.","message":"Version 5.0.0 of `get-amd-module-type` dropped support for Node.js version 12. This preceded the Node.js 18 requirement in v6.0.0.","severity":"breaking","affected_versions":">=5.0.0 <6.0.0"},{"fix":"Be explicit in your choice of API: use `getType(path, callback)` for non-blocking I/O, or `getType.sync(path)` for simpler scripting where blocking is acceptable. Always handle errors for both patterns.","message":"The package offers both asynchronous (`getType(path, callback)`) and synchronous (`getType.sync(path)`) methods for file analysis. Mixing these or mistakenly using the async variant where sync is intended can lead to unexpected behavior or degraded performance due to unnecessary callbacks.","severity":"gotcha","affected_versions":">=4.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure the package is installed (`npm install get-amd-module-type`). If the issue persists, check your Node.js version (`node -v`) and verify it meets the `get-amd-module-type` requirements (e.g., Node.js >=18 for v6.x). Upgrade Node.js or downgrade the package if necessary.","cause":"This error typically occurs if the package is not installed or if the Node.js version is incompatible with the installed package version.","error":"Error: Cannot find module 'get-amd-module-type'"},{"fix":"Ensure your file is treated as CommonJS (e.g., by using `.js` extension in a project without `\"type\": \"module\"` in `package.json`). If you must use `get-amd-module-type` in an ESM file, consider dynamically importing it or using `createRequire` from the `module` module if running in Node.js.","cause":"This indicates you are trying to use CommonJS `require` in an ECMAScript Module (ESM) context without proper setup (e.g., without `createRequire` or a bundler that transpiles CJS).","error":"ReferenceError: require is not defined"},{"fix":"Stick to the documented CommonJS import pattern: `const getType = require('get-amd-module-type');`. The package exports a single function as its main entry point.","cause":"This can happen if you are attempting to import `getType` using `import getType from 'get-amd-module-type'` in an environment that expects CommonJS `module.exports` as a named import, or if the package is not correctly exporting its default function.","error":"TypeError: getType is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}