web icon indicating copy to clipboard operation
web copied to clipboard

Config loader: test fails since Node v22.7.0

Open web-padawan opened this issue 1 year ago • 0 comments

The following error is thrown in CI and can be also reproduced locally using Node 22.7.0.

$ npm run test:node -w @web/config-loader

> @web/[email protected] test:node
> mocha test/**/*.test.js --reporter dot

  11 passing (12ms)
  1 failing

  1) cjs package
       throws when loading module-in-.js:

      AssertionError: expected false to equal true
      + expected - actual

      -false
      +true

Looks like it's caused by the fact that module syntax detection is now enabled by default and Node is now smarter than we expect it to be, which makes the test fail as no exception is thrown as the file is parsed due to syntax detection:

Syntax detection attempts to run ambiguous files as CommonJS, and if the module fails to parse as CommonJS due to ES module syntax, Node.js tries again and runs the file as an ES module. Ambiguous files are those with a .js or no extension, where the nearest parent package.json has no "type" field (either "type": "module" or "type": "commonjs").

I think for now we can workaround this by adding --no-experimental-detect-module flag. This would make the test pass.

web-padawan avatar Aug 29 '24 11:08 web-padawan