question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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 issue

Bug 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.

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:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
nicolo-ribaudocommented, Jan 29, 2021

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 the paths option (Node.js docs)

However, Atom completely overrides the require.resolve function with a custom one, removing support for the paths 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.

1reaction
DeeDeeGcommented, Jan 29, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot find module '@babel/core' - node.js - Stack Overflow
Try running this. npm install @babel/core --save. babel changed their package so your babel-core will not be the same as @babel/core .
Read more >
Configure Babel
Check out the babel.config.json documentation to see more configuration options. ... If it is a relative path, it will be resolved from cwd...
Read more >
babel-plugin-root-import - npm package - Snyk
By default everything is resolved relative to the current working directory. You can change this with the root config option. To use it...
Read more >
@babel/eslint-parser | Yarn - Package Manager
readme. babel. The compiler for writing next generation JavaScript. Gitpod ready-to-code.
Read more >
@babel/core: Versions | Openbase
#15060 Ensure @babel/runtime-corejs3/core-js/*.js can be imported on ... Module not found: Error: Can't resolve 'core-js/modules/es6.array.concat.js' with ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found