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

Cannot import the url package in browser mode #4535

Closed
6 tasks done
guansss opened this issue Nov 18, 2023 · 0 comments · Fixed by #5082
Closed
6 tasks done

Cannot import the url package in browser mode #4535

guansss opened this issue Nov 18, 2023 · 0 comments · Fixed by #5082
Labels
feat: browser Issues and PRs related to the browser runner

Comments

@guansss
Copy link

guansss commented Nov 18, 2023

Describe the bug

When the url package is imported, it's not transpiled to ESM, causing the following errors:

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Suites 2 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

 FAIL  a.test.js [ a.test.js ]
SyntaxError: The requested module '/node_modules/url/url.js?v=a21301ec' does not provide an export named 'parse'
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/2]⎯

 FAIL  b.test.js [ b.test.js ]
ReferenceError: require is not defined
 ❯ ../../../../..//node_modules/url/url.js:26:16

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[2/2]⎯

 Test Files  2 failed (2)
      Tests  no tests
   Start at  00:54:15
   Duration  14.49s (transform 0ms, setup 0ms, collect 0ms, tests 0ms, environment 0ms, prepare 0ms)

I noticed #4337, but this is not quite the same because here url is installed as a dependency, and is imported as "url" instead of "node:url", I would expect it to just work like a normal package.

Reproduction

repo: https://github.com/guansss/repro-vitest-builtin

a.test.js

import { parse } from 'url';
import { test } from 'vitest';

test('parse', () => {
  console.log(parse('http://www.example.com'));
});

b.test.js

import * as url from 'url';
import { test } from 'vitest';

test('parse', () => {
  console.log(url.parse('http://www.example.com'));
});

System Info

System:
    OS: Windows 11 10.0.22621
    CPU: (24) x64 13th Gen Intel(R) Core(TM) i7-13700KF
    Memory: 18.69 GB / 31.86 GB
  Binaries:
    Node: 18.17.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - C:\Program Files\nodejs\yarn.CMD
    npm: 9.6.7 - C:\Program Files\nodejs\npm.CMD
    pnpm: 8.10.5 - C:\Program Files\nodejs\pnpm.CMD
  Browsers:
    Edge: Chromium (119.0.2151.58)
    Internet Explorer: 11.0.22621.1
  npmPackages:
    @vitest/browser: 1.0.0-beta.5 => 1.0.0-beta.5
    vitest: ^1.0.0-beta.5 => 1.0.0-beta.5

Used Package Manager

npm

Validations

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: browser Issues and PRs related to the browser runner
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants