Closed JoshuaWise closed 8 years ago
Closed. This bug was being caused by a custom-hacked version of NPM at my office. Sorry.
I'm having this problem today because of pnpm (6.23.1, but I don't think it's limited to this version).
My project uses pnpm and cypress. Cypress imports this "url" npm module but then Vite is replacing another package's import of the builtin url
module with this npm module, and then my code breaks, with this error specifically:
Uncaught SyntaxError: The requested module '/node_modules/.pnpm/url@0.11.0/node_modules/url/url.js?v=0c7e7bad' does not provide an export named 'default'
I added url
to my vite config's optimizeDeps.exclude
while trying to resolve the problem that when building for production, Vite complained that it could not bundle url
for the browser.
Now I removed that, and both vite dev
and vite build
seem to be working now!
Edit: A few more details here -> https://discord.com/channels/804011606160703521/814182556068085760/915588702489681941
Edit 2: I should note that I had to write a custom (albeit tiny) vite plugin:
Sounds like a vite bug.
Before NPM version 3.0.0, I could use modules that
require()
'd this module, and then go ahead and use the Node coreurl
module all I wanted. But now in NPM@3, the entire dependency tree is installed as flat as possible in thenode_modules
folder. This means that if I use a module that uses this module, I can no longer use the nativeurl
module anymore, because this one overwrites it. I did not put this module in mypackage.json
as a dependency, an yet I am forced to use it. This should NOT be possible. If it's important to provide mirrors of the Node core modules in NPM, they should be under a different name. This wouldn't cause any problems, but it would solve this one.