-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Uncaught SyntaxError: Cannot use import statement outside a module in Rails project #1765
Comments
To answer your question title, you should know how Node.js treat some file as es modules, either:
You may know If your dependencies (not the "dependencies" field in package.json, but libraries your code really depends on) include these dynamic require calls, the best way for esbuild would be you edit these code to "correct" one (not using dynamic require). |
What you are trying to do is not going to work. Passing
It sounds like you are trying to use packages that aren't designed to work on the web. There may not be much you can do about that here. If a library needs
You can read about how import statements work here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import. Specifically you need |
Closing due to age. |
I faced a similar error. Adding If anyone knows why? |
In my Rails project I am facing the following issues. The first issue was a known one as in #946 "ReferenceError: require is not defined". By reading through those issues and PR's I've added the following line to my build (with --banner).
--banner:js='import { createRequire as topLevelCreateRequire } from \"module\";\n const require = topLevelCreateRequire(import.meta.url);'
Now the error beneath occurs. I've already tried set the type to module in the package.json etc.
Uncaught SyntaxError: Cannot use import statement outside a module
This is a webapplication requiring some of the commonJS stuff it seems I've also added
--platform=node
to the build script to fix issues as:ReferenceError: fs is not defined
Is there a way to bundle this all for the web with all requirements?
The text was updated successfully, but these errors were encountered: