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

when switching to ESM modules, this package no longer works #432

Open
Arro opened this issue Oct 30, 2021 · 1 comment
Open

when switching to ESM modules, this package no longer works #432

Arro opened this issue Oct 30, 2021 · 1 comment

Comments

@Arro
Copy link

Arro commented Oct 30, 2021

Once you switch your package.json to type: module, usage of the this package breaks, including utils such as babel-node.

Lets say your .babelrc.cjs looks like this:

module.exports = {
  presets: [
    [
      "@babel/preset-env",
      {
        useBuiltIns: "usage",
        corejs: {
          version: 3,
          proposals: true
        },
        targets: {
          node: "14"
        }
      }
    ]
  ],
  plugins: [
    [
      "module-resolver",
      {
        alias: {
          src: "./src"
        },
        extensions: [".js"]
      }
    ]
  ]
}

If you have a file like src/nested/very/deep.js and you want to load it in another file like src/nested-elsewhere/also/very/deep.js

$ babel-node src/nested-elsewhere/also/very/deep.js

results in:

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'src' imported from /Users/myuser/Code/myproject/src/nested-elsewhere/also/very/deep.js

To reaffirm, this only happens once switching to ESM modules.

@Arro Arro changed the title when switching to ESM modules, babel-node no longer works when switching to ESM modules, this package no longer works Oct 30, 2021
@kodikos
Copy link

kodikos commented Feb 10, 2022

I'm getting the same. I spotted this on a competitor's issues list, which may indicate the cause (ilearnio/module-alias#59).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants