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

Babel-node not working with "type": "module" in package.json #11108

Open
subhero24 opened this issue Feb 7, 2020 · 4 comments
Open

Babel-node not working with "type": "module" in package.json #11108

subhero24 opened this issue Feb 7, 2020 · 4 comments
Assignees

Comments

@subhero24
Copy link

@subhero24 subhero24 commented Feb 7, 2020

I have the following script that I'm running with npx babel-node script.js

let a = 0;
let b = 1;
console.log(a ?? b);

It executes fine with my babel config

{
	"plugins": ["@babel/plugin-proposal-nullish-coalescing-operator"]
}

When I add "type": "module" to my package.json file, the npx babel-node script.js command fails to run and I get the error SyntaxError: Unexpected token '?'.

So it seems specifying my package as module, prevents babel-node from loading the babel config?

@subhero24 subhero24 changed the title Babel-node not working with type: module in package.json Babel-node not working with "type": "module" in package.json Feb 7, 2020
@babel-bot

This comment has been minimized.

Copy link
Collaborator

@babel-bot babel-bot commented Feb 7, 2020

Hey @subhero24! 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."

@nicolo-ribaudo

This comment has been minimized.

Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented Feb 7, 2020

This is currently expected. @babel/register (used by @babel/node) only works with CommonJS scripts, because Node.js doesn't have a stable API yet to intercept ES modules loading.

@JLHwung

This comment has been minimized.

Copy link
Contributor

@JLHwung JLHwung commented Feb 9, 2020

Worth add a note to https://babeljs.io/docs/en/babel-register that babel-register does not support compiling native Node.js es modules on the fly.

@sidntrivedi012

This comment has been minimized.

Copy link
Contributor

@sidntrivedi012 sidntrivedi012 commented Feb 10, 2020

I would like to help out in this doc fix.

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

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.