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

Compiling for nodes aborts with "SyntaxError: Cannot use import statement outside a module" #832

Open
halloleo opened this issue Nov 25, 2022 · 3 comments

Comments

@halloleo
Copy link

I'm trying to use the sample nodejs_demo.py with node, so I compile it with

transcrypt -b -p .none  nodejs_demo.py  

However when I run this as

node ./__target__/nodejs_demo.js

I get the error "SyntaxError: Cannot use import statement outside a module".

How can I fix this?


Environment

  • Transcrypt 3.9.0
  • Node 14.17.3
@JennaSys
Copy link
Collaborator

I got it to work using the instructions in the readme.txt for the demo. After compiling I ran it with the following node command (note that the command in the readme isn't quite accurate):

node nodejs_demo.bundle.js 8080

But I run into the same issue as you using the -p .none Transcrypt compile option where the import statement can't be used with commonJS. But then setting "type": "module" in the package.json like the node error message suggests, results in the require() function not working in the compiled ES module.

@halloleo
Copy link
Author

Thank you so much @JennaSys! The rollup bundler does the trick indeed! I didn't look at the README to the demo, sorry, I just had followed the instructions in the doco.

@JennaSys
Copy link
Collaborator

JennaSys commented Nov 28, 2022

I'm not quite familiar enough with JS and Node off the top of my head to figure out how to fix what is shown in the docs for the demo, but I'm glad the other method works for you.

This issue should be left open since both the demo readme and the docs need to be fixed.

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

No branches or pull requests

2 participants