SyntaxError: Cannot use 'import.meta' outside a module
See original GitHub issueFiling this as a close duplicate of #9299 because that issue is locked, and with the release of Node v12, the createRequireFromPath boilerplate has become more widespread, and it involves import.meta.url
:
import {createRequireFromPath as createRequire} from 'module';
import {fileURLToPath as fromURL} from 'url';
const require = createRequire(fromURL(import.meta.url));
As a Babel end-user, I don’t know how to work around the SyntaxError: Cannot use 'import.meta' outside a module
, and leaving that issue open might allow someone more knowledgeable to offer a solution.
I personally find it mildly infuriating when conversations are locked without any spam or abuse problems, because nether I nor others can add anything that might help each other. Sometimes the “final word” from the core team is less than intelligible to those new to the topic.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:7 (3 by maintainers)
Top Results From Across the Web
[Bug]: SyntaxError: Cannot use 'import.meta' outside a module ...
import.meta is an ESM only feature and cannot be used in CJS (aka when using require ), so you need the files to...
Read more >Uncaught SyntaxError: Cannot use 'import.meta' outside a ...
This has been asked already, and the answer is here. You just need to adjust your module.exports = { output: { uniqueName: "MyProj", ......
Read more >Cannot use import statement outside a module' | HackerNoon
This error arises when we try to use import inside of a project which is not set up for modules - so let's...
Read more >import.meta - JavaScript - MDN Web Docs
The import.meta meta-property is available in JavaScript modules; using import.meta outside of a module (including direct eval() within a ...
Read more >How to fix "cannot use import statement outside a module"
This error occurs for one reason: you're trying to use import and you're not inside an ES module. It can happen in a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
That error isn’t thrown by Babel. Babel throws
'import' and 'export' may appear only with 'sourceType: "module"'
maybe the error can be that i havent put the export as default export?