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:closed
  • Created 5 years ago
  • Reactions:66
  • Comments:53 (8 by maintainers)

github_iconTop GitHub Comments

110reactions
itshizhancommented, May 21, 2018

since you use type=“module”,why use parcel?

29reactions
tarepancommented, May 21, 2018

Mainly for module resolution.
And for old browser users (ES module not supported, need Bundle.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

ES Module type=module cause "parcelRequire is not defined ...
When I removed type="module" from script element, no error observed. It suggest that we can avoid error by avoiding type="module" for parcel. ...
Read more >
DFKaye on Twitter: "HACK wrt https://t.co/oTjRrybaNA, when ...
bug report Using ES Module in main HTML cause "parcelRequire is not defined" error. If we use type="module", minimal code in Getting Started...
Read more >
equire is not defined in es module scope, you can use import ...
Using ES Module in main HTML cause "parcelRequire is not defined" error. ... It suggest that we can avoid error by avoiding type="module"...
Read more >
Parcel
Parcel can build libraries for multiple targets at once! For example, your source code can be compiled to a modern ES module, a...
Read more >
ReferenceError: exports is not defined in ES module scope
As I understand the node runtime environment doesn't understand exports keyword and that is what is causing the problem. I intend to run...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found