JS package not loading when configured with relative path plugin "./plugin-name.js" defined in .babelrc.js -- "Error: Cannot find module './plugin-name.js'" -- started with @babel/core 7.12.10
See original GitHub issueBug Report
- I would like to work on a fix!
Happy to help with follow-up questions and tracking down the issue, but I’m so-so with JS. I’ll post a PR if it becomes clear to me what exactly needs to change.
Current behavior
When trying to load modules configured with @babel/core
7.12.10, with a plugin defined as a relative path in .babelrc.js
, the module does not load.
The plugin JS file, defined in .babelrc.js
as ./plugin-name-here.js
, is not resolved properly.
- Link to failing CI run: https://github.com/DeeDeeG/github/runs/1792141366?check_suite_focus=true#step:7:14
Require stack (click to expand):
Error: Cannot find module './assert-messages-plugin.js'
Require stack:
- /home/runner/work/github/github/node_modules/@babel/core/lib/config/files/plugins.js
- /home/runner/work/github/github/node_modules/@babel/core/lib/config/files/index.js
- /home/runner/work/github/github/node_modules/@babel/core/lib/index.js
- /home/runner/work/github/github/node_modules/@atom/babel7-transpiler/lib/index.js
- /home/runner/work/_temp/atom/usr/share/atom-nightly/resources/app.asar/src/package-transpilation-registry.js
- /home/runner/work/_temp/atom/usr/share/atom-nightly/resources/app.asar/src/compile-cache.js
- /home/runner/work/_temp/atom/usr/share/atom-nightly/resources/app.asar/static/index.html
at Module._resolveFilename (internal/modules/cjs/loader.js:627:15)
at Module._resolveFilename (/home/runner/work/_temp/atom/usr/share/atom-nightly/resources/electron.asar/common/reset-search-paths.js:41:16)
at Function.Module._resolveFilename (/home/runner/work/_temp/atom/usr/share/atom-nightly/resources/app.asar/src/module-cache.js:336:28)
at require.resolve (/home/runner/work/_temp/atom/usr/share/atom-nightly/resources/app.asar/src/native-compile-cache.js:70:23)
at resolveStandardizedName (/home/runner/work/github/github/node_modules/@babel/core/lib/config/files/plugins.js:100:7)
at resolvePlugin (/home/runner/work/github/github/node_modules/@babel/core/lib/config/files/plugins.js:44:10)
at loadPlugin (/home/runner/work/github/github/node_modules/@babel/core/lib/config/files/plugins.js:52:20)
at createDescriptor (/home/runner/work/github/github/node_modules/@babel/core/lib/config/config-descriptors.js:154:9)
at /home/runner/work/github/github/node_modules/@babel/core/lib/config/config-descriptors.js:109:50
at Array.map (<anonymous>)
at createDescriptors (/home/runner/work/github/github/node_modules/@babel/core/lib/config/config-descriptors.js:109:29)
at createPluginDescriptors (/home/runner/work/github/github/node_modules/@babel/core/lib/config/config-descriptors.js:105:10)
at plugins (/home/runner/work/github/github/node_modules/@babel/core/lib/config/config-descriptors.js:40:19)
at mergeChainOpts (/home/runner/work/github/github/node_modules/@babel/core/lib/config/config-chain.js:415:26)
at /home/runner/work/github/github/node_modules/@babel/core/lib/config/config-chain.js:374:7
at Generator.next (<anonymous>)
at loadFileChain (/home/runner/work/github/github/node_modules/@babel/core/lib/config/config-chain.js:228:24)
at loadFileChain.next (<anonymous>)
at buildRootChain (/home/runner/work/github/github/node_modules/@babel/core/lib/config/config-chain.js:135:29)
at buildRootChain.next (<anonymous>)
at loadPrivatePartialConfig (/home/runner/work/github/github/node_modules/@babel/core/lib/config/partial.js:101:62)
at loadPrivatePartialConfig.next (<anonymous>)
at loadFullConfig (/home/runner/work/github/github/node_modules/@babel/core/lib/config/full.js:57:46)
at loadFullConfig.next (<anonymous>)
at Object.transform (/home/runner/work/github/github/node_modules/@babel/core/lib/transform.js:25:45)
at transform.next (<anonymous>)
at evaluateSync (/home/runner/work/github/github/node_modules/gensync/index.js:251:28)
at Object.sync (/home/runner/work/github/github/node_modules/gensync/index.js:89:14)
at /home/runner/work/github/github/node_modules/@atom/babel7-transpiler/lib/index.js:54:28
at withBabelEnv (/home/runner/work/github/github/node_modules/@atom/babel7-transpiler/lib/index.js:18:15)
Input Code
N/A, I think it doesn’t matter what the actual code to transpile is.
Expected behavior
The plugin should load and be used without errors (as it did all the way through @babel/core
7.12.9).
Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)
- Filename:
.babelrc.js
module.exports = {
sourceMaps: "inline",
plugins: [
"babel-plugin-relay",
"./assert-messages-plugin.js",
"@atom/babel-plugin-chai-assert-async",
"@babel/plugin-proposal-class-properties",
// Needed for esprima
"@babel/plugin-proposal-object-rest-spread",
],
presets: [
["@babel/preset-env", {
targets: {electron: process.versions.electron || process.env.ELECTRON_VERSION}
}],
"@babel/preset-react"
],
env: {
coverage: {
plugins: ["babel-plugin-istanbul"]
}
}
}
Environment
Linux CI Environment
System:
OS: Linux 5.4 Ubuntu 18.04.5 LTS (Bionic Beaver)
Binaries:
Node: 12.4.0 - ~/work/_temp/atom/usr/share/atom-nightly/resources/app/apm/bin/node
Yarn: 1.22.5 - /usr/bin/yarn
npm: 6.14.8 - ~/work/_temp/atom/usr/share/atom-nightly/resources/app/apm/bin/npm
npmPackages:
@babel/core: 7.12.10 => 7.12.10
@babel/generator: 7.8.0 => 7.8.0
@babel/plugin-proposal-class-properties: 7.8.0 => 7.8.0
@babel/plugin-proposal-object-rest-spread: 7.8.0 => 7.8.0
@babel/preset-env: 7.12.1 => 7.12.1
@babel/preset-react: 7.8.0 => 7.8.0
babel-plugin-istanbul: 5.2.0 => 5.2.0
babel-plugin-relay: 5.0.0 => 5.0.0
eslint: 6.8.0 => 6.8.0
macOS CI Environment
System:
OS: macOS 10.15.7
Binaries:
Yarn: 1.22.5 - ~/.yarn/bin/yarn
npm: 6.14.8 - ~/work/_temp/atom/Atom Nightly.app/Contents/Resources/app/apm/bin/npm
npmPackages:
@babel/core: 7.12.10 => 7.12.10
@babel/generator: 7.8.0 => 7.8.0
@babel/plugin-proposal-class-properties: 7.8.0 => 7.8.0
@babel/plugin-proposal-object-rest-spread: 7.8.0 => 7.8.0
@babel/preset-env: 7.12.1 => 7.12.1
@babel/preset-react: 7.8.0 => 7.8.0
babel-plugin-istanbul: 5.2.0 => 5.2.0
babel-plugin-relay: 5.0.0 => 5.0.0
eslint: 6.8.0 => 6.8.0
Windows CI Environment
System:
OS: Windows 10 10.0.17763
Binaries:
Node: 14.15.4 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.10 - C:\npm\prefix\yarn.CMD
npm: 6.14.10 - C:\Program Files\nodejs\npm.CMD
npmPackages:
@babel/core: 7.12.10 => 7.12.10
@babel/generator: 7.8.0 => 7.8.0
@babel/plugin-proposal-class-properties: 7.8.0 => 7.8.0
@babel/plugin-proposal-object-rest-spread: 7.8.0 => 7.8.0
@babel/preset-env: 7.12.1 => 7.12.1
@babel/preset-react: 7.8.0 => 7.8.0
babel-plugin-istanbul: 5.2.0 => 5.2.0
babel-plugin-relay: 5.0.0 => 5.0.0
eslint: 6.8.0 => 6.8.0
Possible Solution
Not sure.
Additional context
I’m trying to update Atom’s github
package to the latest @babel/core
v7, but this error is stopping me from doing so.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
This is an Atom bug. Starting from Babel 7.10.0 we started using the
require.resolve
function in Node.js >= 8.9, because it supports thepaths
option (Node.js docs)However, Atom completely overrides the
require.resolve
function with a custom one, removing support for thepaths
option. Babel (as well as most of the packages on npm) assumes that the Node.js API hasn’t been modified in ways incompatible with the built-in Node.js functions, so there isn’t much that we can do to fix this.Oh okay, I thing the version above was just a typo (7.10) I see the PR: https://github.com/babel/babel/pull/12439 landed for 7.12.10
Thanks.