Skip to content
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

[bugfix] resolve 'ERR_REQUIRE_ESM' error occurring on 'npm run test' #68

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

atla5
Copy link
Member

@atla5 atla5 commented May 7, 2020

Background

  • this is a configuration problem that started occurring, to my knowledge, without any major code change on our end.
  • we're using the open-wc testing configuration described in their documentation with a single-line change to include our bundle.css in the files

Description of the Bug

  • running npm run test no longer runs the karma testing suite as it used to and prints an error related to ERR_REQUIRE_ESM

Output

$ npm run test
$ karma start karma.conf.js
07 05 2020 16:05:24.564:ERROR [config]: Error in config file!
  Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/aidans/projects/wc/karma.conf.js
require() of ES modules is not supported.
require() of /Users/aidans/projects/wc/karma.conf.js from /usr/local/lib/node_modules/karma/lib/config.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename karma.conf.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/aidans/projects/wc/package.json.

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1172:13)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Module.require (internal/modules/cjs/loader.js:1042:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.parseConfig (/usr/local/lib/node_modules/karma/lib/config.js:357:22)
    at new Server (/usr/local/lib/node_modules/karma/lib/server.js:67:24)
    at Object.exports.run (/usr/local/lib/node_modules/karma/lib/cli.js:295:7)
    at Object.<anonymous> (/usr/local/lib/node_modules/karma/bin/karma:3:23)
    at Module._compile (internal/modules/cjs/loader.js:1156:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47

Attempted Fixes

  1. remove "type": "module" from package.json -> no tests are run, they just hang.
$ karma start
Browserslist: caniuse-lite is outdated. Please run next command `npm update`

START:
07 05 2020 16:00:58.237:INFO [karma-server]: Karma v4.4.1 server started at http://0.0.0.0:9876/
07 05 2020 16:00:58.238:INFO [launcher]: Launching browsers ChromeHeadlessNoSandbox with concurrency unlimited
07 05 2020 16:00:58.243:INFO [launcher]: Starting browser ChromeHeadless
07 05 2020 16:00:58.606:INFO [HeadlessChrome 81.0.4044 (Mac OS X 10.15.4)]: Connected on socket l9XHWr6ckrpTRUrqAAAA with id 67019134
Resolved to invalid user agent: {"family":"Chrome","version":"81.0.4044"}. Using max compatibility mode. Try updating your dependencies, or file an issue with a reproduction.

07 05 2020 16:01:28.609:WARN [HeadlessChrome 81.0.4044 (Mac OS X 10.15.4)]: Disconnected (0 times), because no message in 30000 ms.
HeadlessChrome 81.0.4044 (Mac OS X 10.15.4) ERROR
  Disconnected, because no message in 30000 ms.
07 05 2020 16:01:28.612:WARN [framework.snapshot]: Snapshot data is unavailable

Finished in 30.002 secs / 0 secs @ 16:01:28 GMT-0400 (Eastern Daylight Time)
  1. rename the karma.conf.js to karma.conf.cjs and update command to karma start karma.conf.cjs -> no tests are run, and they just hang. even after npm update
$ karma start karma.conf.cjs
Browserslist: caniuse-lite is outdated. Please run next command `npm update`

START:
07 05 2020 16:04:49.810:INFO [karma-server]: Karma v4.4.1 server started at http://0.0.0.0:9876/
07 05 2020 16:04:49.811:INFO [launcher]: Launching browsers ChromeHeadlessNoSandbox with concurrency unlimited
07 05 2020 16:04:49.816:INFO [launcher]: Starting browser ChromeHeadless
07 05 2020 16:04:50.267:INFO [HeadlessChrome 81.0.4044 (Mac OS X 10.15.4)]: Connected on socket -prvuOvGc-8ilzMLAAAA with id 98024656
Resolved to invalid user agent: {"family":"Chrome","version":"81.0.4044"}. Using max compatibility mode. Try updating your dependencies, or file an issue with a reproduction.

^C
  1. try adding --experimental-modules flag for node -> no effect

Steps to Reproduce

$ npm i
$ npm run test

Screenshots

open-wc karma.js side-by-side

@atla5 atla5 added bug Something isn't working in progress labels May 7, 2020
@atla5 atla5 added help wanted Extra attention is needed and removed in progress labels Sep 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant