ES Module type=module cause "parcelRequire is not defined" error
See original GitHub issue🐛 bug report
Using ES Module in main HTML cause “parcelRequire is not defined” error.
If we use type=“module”, minimal code in Getting Started (Parcel official) make this error.
🎛 Configuration (.babelrc, package.json, cli command)
zero configuration.
🤔 Expected Behavior
If we write super simple code with ES Module like below,
<!-- index.html -->
<html>
<body>
<script src="./index.js" type="module"></script>
</body>
</html>
// index.js
console.log("hello parcel");
I hope it is bundled properly and get “hello parcel” in console without error.
😯 Current Behavior
In console,
hello parcel. index.js 1
Uncaught ReferenceError: parcelRequire is not defined at test.904c6489.js:10
💁 Possible Solution
Apparently ES Module cause this error.
When I removed type=“module” from script element, no error observed.
It suggest that we can avoid error by avoiding type=“module” for parcel.
But I think this approach is not good.
ES Module (type=“module”) is generally available (now 2018-05, all popular browsers supported!!), so ES module is straight forward way to import module.
🔦 Context
I do not know what problem is caused by this error.
🌍 Your Environment
| Software | Version(s) |
|---|---|
| Parcel | parcel-bundler@1.8.1 |
| Node | (problem happen both) 8.9.3 & 9.11.1 |
| npm/Yarn | |
| Operating System | Windows10 Pro, build 17134 |
Thank you good library, I hope this project become better and better.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:66
- Comments:53 (8 by maintainers)
Top Related StackOverflow Question
since you use type=“module”,why use parcel?
Mainly for module resolution.
And for old browser users (ES module not supported, need Bundle.)