parcel: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module (weak-lru-cache)

πŸ› bug report

i tried to start with the basic example https://parceljs.org/getting-started/webapp/ adding all the files and run npx parcel src/index.html

πŸŽ› Configuration (.babelrc, package.json, cli command)

{
  "name": "can-parcel",
  "version": "1.0.0",
  "description": "",
  "source": "src/index.html",
  "scripts": {
    "start": "parcel",
    "watch": "parcel watch",
    "build": "parcel build",
    "foo": "parcel src/app.js --no-cache"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "parcel": "^2.0.0"
  }
}

πŸ€” Expected Behavior

i should open http://localhost:1234/ on the browser and see β€œtest” in the console.

😯 Current Behavior

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: C:\Users\.........\node_modules\weak-lru-cache\index.js
require() of ES modules is not supported.
require() of C:\Users\.........\node_modules\weak-lru-cache\index.js from C:\Users\.........\node_modules\lmdb-store\caching.js is an ES module file as it is a .js file whose nearest parent package.json contain
s "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from C:\Users\.........\node_modules\weak-lru-cache\package.json.

πŸ’» Code Sample

src/index.html

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8"/>
  <title>My First Parcel App</title>
  <script type="module" src="src/app.js"></script>
</head>
<body>
<h1>Hello, World!</h1>
</body>
</html>

src/app.js

console.log("test");

🌍 Your Environment

Software Version(s)
Parcel 2.0.0
Node v12.16.3
npm/Yarn 8.1.0
Operating System Windows 10

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 15 (3 by maintainers)

Most upvoted comments

@aaron-goff That seems to work correctly for me