web icon indicating copy to clipboard operation
web copied to clipboard

Running fails with "cannot find module"

Open nzakas opened this issue 1 year ago • 0 comments

I'm trying to run web-test-runner inside of a monorepo and I get this error:

$ npm test -w packages/memory

> [email protected] test
> web-test-runner --node-resolve tests/*.js

node:internal/modules/cjs/loader:452
      throw err;
      ^

Error: Cannot find module 'C:\Users\nzaka\projects\humanwhocodes\fsx\packages\web\node_modules\proxy-agent\dist\index.js'. Please verify that the package.json has a valid "main" entry
    at tryPackage (node:internal/modules/cjs/loader:444:19)
    at Module._findPath (node:internal/modules/cjs/loader:715:18)
    at Module._resolveFilename (node:internal/modules/cjs/loader:1130:27)
    at Module._load (node:internal/modules/cjs/loader:985:27)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18)
    at Object.<anonymous> (C:\Users\nzaka\projects\humanwhocodes\fsx\packages\web\node_modules\@puppeteer\browsers\lib\cjs\httpUtil.js:46:23)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32) {
  code: 'MODULE_NOT_FOUND',
  path: 'C:\\Users\\nzaka\\projects\\humanwhocodes\\fsx\\packages\\web\\node_modules\\proxy-agent\\package.json',
  requestPath: 'proxy-agent'
}

Node.js v20.11.0
npm ERR! Lifecycle script `test` failed with error: 
npm ERR! Error: command failed
npm ERR!   in workspace: [email protected]
npm ERR!   at location: C:\Users\nzaka\projects\humanwhocodes\fsx\packages\web 

Some other details about the project:

  • Using ESM via package.json "type": "module"
  • Monorepo using npm workspaces
Environment Info

@web/test-runner v0.18.0

$ npx envinfo

  System:
    OS: Windows 10 10.0.19045
  Binaries:
    Node: 20.11.0 - C:\Program Files\nodejs\node.EXE
    npm: 7.10.0 - C:\Program Files\nodejs\npm.CMD   

Reproduction steps

  1. Clone https://github.com/humanwhocodes/fsx
  2. npm install
  3. cd packages/memory
  4. npm i @web/test-runner
  5. Update "test" script in package.json to be "web-test-runner tests/*.js --node-resolve"
  6. Run npm test

nzakas avatar Jan 24 '24 21:01 nzakas