Skip to content

🐛 BUG: vitest unable resolve "url" module #6214

@elct9620

Description

@elct9620

Which Cloudflare product(s) does this pertain to?

Workers Vitest Integration

What version(s) of the tool(s) are you using?

3.63.1 [Wrangler], 0.4.9 [@cloudflare/vitest-pool-workers], 1.5.3 [vitest]

What version of Node are you using?

20.12.2

What operating system and version are you using?

Mac Sonoma 14.4.1

Describe the Bug

Observed behavior

When running npm run test with vitest the error is displayed on the console.

 FAIL  test/index.spec.ts [ test/index.spec.ts ]
Error: No such module "Users/elct9620/Workspace/StarPortal/line-bot-testing-lab/node_modules/axios/lib/platform/node/classes/url".
  imported from "Users/elct9620/Workspace/StarPortal/line-bot-testing-lab/node_modules/axios/lib/platform/node/classes/URLSearchParams.js"

Use wrangler deploy and works correctly in the CloudFlare

Expected behavior

The test should passed.

Steps to reproduce

Please provide the following:

  1. npm init cloudflare
  • Enable TypeScript
  • Enable git
  • Don't deploy
  1. npm i -D axios
  2. Add import axios from 'axios' to the header in src/index.ts
  3. Add axios.get('https://example.com') to the handler in src/index.ts

The axios is required by SDK (https://github.com/line/line-bot-sdk-nodejs) everything is default from the template.

Please provide a link to a minimal reproduction

No response

Please provide any relevant error logs

workerd/server/server.c++:2835: error: Fallback service failed to fetch module; payload = ; spec = /?specifier=%2Fprivate%2Ftmp%2Fcf-axios%2Fnode_modules%2Faxios%2Flib%2Fplatform%2Fnode%2Fclasses%2Furl&referrer=%2Fprivate%2Ftmp%2Fcf-axios%2Fnode_modules%2Faxios%2Flib%2Fplatform%2Fnode%2Fclasses%2FURLSearchParams.js&rawSpecifier=url
 ❯ test/index.spec.ts (0)

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Suites 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

 FAIL  test/index.spec.ts [ test/index.spec.ts ]
Error: No such module "private/tmp/cf-axios/node_modules/axios/lib/platform/node/classes/url".
  imported from "private/tmp/cf-axios/node_modules/axios/lib/platform/node/classes/URLSearchParams.js"
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯

 Test Files  1 failed (1)
      Tests  no tests
   Start at  18:23:16
   Duration  0ms


 FAIL  Tests failed. Watching for file changes...
       press h to show help, press q to quit

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething that isn't workingvitestRelating to the Workers Vitest integration

    Type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions