Registry / serialization / get-amd-module-type

get-amd-module-type

JSON →
library6.0.2jsnpmunverified

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.

npm install get-amd-module-type
INSTALL
IMPORT
SIG · GET-AMD-MODULE-TYP
G
get-amd-module-type
serializationjavascriptv6.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

getType
const getType = require('get-amd-module-type');
import getType from 'get-amd-module-type';
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.
getType.sync
const getType = require('get-amd-module-type'); const type = getType.sync('path/to/file.js');
import { sync } from 'get-amd-module-type';
`sync` is a method property of the `getType` function, not a named export. Ensure you call it from the main `getType` export.
getType.fromSource
const getType = require('get-amd-module-type'); const type = getType.fromSource('define([\'dep\'], function(){});');
import { fromSource } from 'get-amd-module-type';
`fromSource` is a method property of the `getType` function, not a named export. It allows direct analysis of module source strings.

Demonstrates asynchronous and synchronous file analysis, as well as direct source code string analysis using the `get-amd-module-type` package.

const getType = require('get-amd-module-type'); const path = require('path'); const fs = require('fs'); // Example file content (replace with actual file system interaction in a real app) const exampleFilePath = path.join(__dirname, 'example-amd-module.js'); fs.writeFileSync(exampleFilePath, "define('myModule', ['dep1', 'dep2'], function(d1, d2) { return {}; });"); console.log('--- Asynchronous File Analysis ---'); getType(exampleFilePath, (error, type) => { if (error) { console.error('Async Error:', error.message); return; } console.log(`Async type for '${exampleFilePath}': ${type}`); // Expected: named }); console.log('\n--- Synchronous File Analysis ---'); try { const syncType = getType.sync(exampleFilePath); console.log(`Sync type for '${exampleFilePath}': ${syncType}`); // Expected: named } catch (error) { console.error('Sync Error:', error.message); } console.log('\n--- From Source String Analysis ---'); const sourceCode = "define(function(require){ return {}; });"; const sourceType = getType.fromSource(sourceCode); console.log(`Type from source ('${sourceCode.substring(0, 20)}...'): ${sourceType}`); // Expected: factory // Clean up example file fs.unlinkSync(exampleFilePath);
Debug
Known issues
breakingVersion 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.
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`).
affects: >=6.0.0
breakingVersion 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.
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.
affects: >=5.0.0 <6.0.0
gotchaThe 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.
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.
affects: >=4.0.0
Errors
Common errors & fixes
Error: Cannot find module 'get-amd-module-type'
This error typically occurs if the package is not installed or if the Node.js version is incompatible with the installed package version.
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.
ReferenceError: require is not defined
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).
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.
TypeError: getType is not a function
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.
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.
Upgrade
Version history
6.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
get-amd-module-type — npm install get-amd-module-type · libregistry