Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 #12715

Closed
1 task
DeeDeeG opened this issue Jan 29, 2021 · 6 comments
Labels
i: bug i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@DeeDeeG
Copy link

DeeDeeG commented Jan 29, 2021

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.

@babel-bot
Copy link
Collaborator

Hey @DeeDeeG! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite."

@DeeDeeG DeeDeeG changed the title JS package not loading after compiled 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 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 Jan 29, 2021
@nicolo-ribaudo
Copy link
Member

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.

@nicolo-ribaudo
Copy link
Member

(I'm closing this and cross-posting my answer in the atom/github issue)

@DeeDeeG
Copy link
Author

DeeDeeG commented Jan 29, 2021

I'm not sure if this changes anything, but it was (surprisingly) working through to @babel/core 7.12.9.

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Jan 29, 2021

Yeah, before 7.12.10 we were always using a polyfill for require.resolve. We switched to only using the polyfill on older Node.js versions without support for the paths option.

@DeeDeeG
Copy link
Author

DeeDeeG commented Jan 29, 2021

Oh okay, I thing the version above was just a typo (7.10) I see the PR: #12439 landed for 7.12.10

Thanks.

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 1, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: bug i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

3 participants