{"id":19104,"library":"babel-plugin-module-extension-resolver","title":"babel-plugin-module-extension-resolver","description":"Babel plugin that resolves and maps module extensions in import/require statements. Version 1.0.0 is the latest stable release, with maintenance releases planned when necessary. It transforms extensionless imports to explicit extensions (e.g., './dir/lib' -> './dir/lib.js'), configurable via srcExtensions, dstExtension, and extensionsToKeep options. Unlike babel-plugin-extension-resolver, it supports TypeScript, dynamic imports, and export from syntax. Works with CommonJS and ES modules.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/shimataro/babel-plugin-module-extension-resolver","tags":["javascript","babel","babel-plugin"],"install":[{"cmd":"npm install babel-plugin-module-extension-resolver","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-module-extension-resolver","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-module-extension-resolver","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"symbol":"default","correct":"no import needed; use via .babelrc plugins array"}],"quickstart":{"code":"// Install\nnpm i -D babel-plugin-module-extension-resolver\n\n// .babelrc\n{\n  \"plugins\": [\"module-extension-resolver\"]\n}\n\n// Input: src/main.js\nrequire(\"./dir/lib\");\nrequire(\"./dir/lib.js\");\nrequire(\"./dir\");\nrequire(\"./settings\");\n\n// Output after Babel:\nrequire(\"./dir/lib.js\");\nrequire(\"./dir/lib.js\");\nrequire(\"./dir/index.js\");\nrequire(\"./settings.json\");","lang":"javascript","description":"Shows basic usage: installation, .babelrc configuration, and how extensionless imports are resolved to .js (or .json kept)."},"warnings":[{"fix":"Update .babelrc to use new option names: set 'srcExtensions', 'dstExtension', and 'extensionsToKeep' instead of 'extensions' and 'map'.","message":"Options changed in v0.3.0: 'extensions' renamed to 'srcExtensions', 'map' replaced by 'extensionsToKeep' and new 'dstExtension'.","severity":"breaking","affected_versions":"<0.3.0"},{"fix":"Upgrade Node.js to version 8 or higher.","message":"Node.js >=8.0.0 required since v0.2.0.","severity":"breaking","affected_versions":">=0.2.0"},{"fix":"Upgrade to v1.0.0-rc.2 or later to resolve dynamic imports.","message":"Dynamic imports support added in v1.0.0-rc.2; previous versions ignore dynamic import() calls.","severity":"breaking","affected_versions":"<1.0.0-rc.2"},{"fix":"Ensure all relative import paths start with './' or '../' to be resolved. For absolute or bare specifiers, consider using other plugins or webpack aliases.","message":"Module paths not beginning with '.' (e.g., 'dir') are not resolved; they are left unchanged.","severity":"gotcha","affected_versions":"all"},{"fix":"Pass '--keep-file-extension' to Babel CLI or set 'extensionsToKeep' to preserve specific extensions like '.mjs'.","message":"The plugin transforms imports regardless of file extension; use 'keepFileExtension' Babel option or set 'extensionsToKeep' to avoid unwanted changes.","severity":"gotcha","affected_versions":"all"},{"fix":"Set 'dstExtension' option to '.mjs' or '.cjs' as needed. For ES modules with TypeScript, set \"modules\": false in @babel/preset-env.","message":"The dstExtension default is '.js'; for TypeScript projects, ensure output extension matches your target (e.g., '.mjs' for ES modules).","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run 'npm install -D babel-plugin-module-extension-resolver' and use 'module-extension-resolver' (not full path) in .babelrc.","cause":"Plugin not installed or path incorrect in .babelrc.","error":"Error: Cannot find module 'babel-plugin-module-extension-resolver'"},{"fix":"Use ES module syntax (import) instead of require, or set @babel/preset-env modules to 'auto' or 'commonjs'.","cause":"Using CommonJS require in ES module context; plugin works but Babel may not transform if modules are set to false.","error":"ReferenceError: require is not defined (when using ES modules)"},{"fix":"Ensure options are specified as: [\"module-extension-resolver\", { ... }].","cause":"Invalid options syntax in .babelrc; likely missing array brackets around plugin options.","error":"TypeError: Cannot read property 'replace' of undefined"},{"fix":"Verify the source file exists with one of the srcExtensions. Check 'srcExtensions' list includes the file extension used. If file is .ts, ensure '.ts' is in srcExtensions.","cause":"File does not exist and plugin cannot resolve; or extension mapping leads to missing file.","error":"Module not found: Error: Can't resolve './dir/lib' in '...'"},{"fix":"Update Babel to version 7.8.0 or later, or ensure @babel/plugin-syntax-dynamic-import is included.","cause":"Babel parser version too old to support import() syntax.","error":"Unexpected token (Error when parsing dynamic import)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}