error: [plugin: vite:dep-pre-bundle] Failed to resolve entry for package "fs".
kanagucalmet opened this issue ยท comments
error: [plugin: vite:dep-pre-bundle] Failed to resolve entry for package "fs". The package may have incorrect main/module/exports specified in its package.json
while running my exisiting nuxtjs app with vitejs
@kanagucalmet Could you provide a reproduction?
๐งช Vite mode is experimental and some nuxt modules might be incompatible 11:31:17
If found a bug, please report via https://github.com/nuxt/vite/issues with a minimal reproduction.
Unstable server-side rendering is enabled
WARN Address 0.0.0.0:5000 is already in use. 11:31:20
โน Trying a random port... 11:31:20
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ
โ Nuxt @ v2.15.4 โ
โ โ
โ โธ Environment: development โ
โ โธ Rendering: server-side โ
โ โธ Target: server โ
โ โ
โ Listening: http://192.168.5.103:39761/ โ
โ โ
โ โก Vite Mode Enabled (v0.1.1) โ
โ โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โน Preparing project for development 11:31:25
โน Initial build may take a while 11:31:25
โ Builder initialized 11:31:25
โ Nuxt files generated 11:31:27
node_modules/vite/dist/node/chunks/dep-fc2895ac.js:38154:14: error: [plugin: vite:dep-pre-bundle] Failed to resolve entry for package "fs". The package may have incorrect main/module/exports specified in its package.json.
38154 โ throw new Error(Failed to resolve entry for package "${id}".
+
โต ^
at resolvePackageEntry (/home/kanagu/Desktop/portal/test/vite-nuxt/node_modules/vite/dist/node/chunks/dep-fc2895ac.js:38154:15)
at tryNodeResolve (/home/kanagu/Desktop/portal/test/vite-nuxt/node_modules/vite/dist/node/chunks/dep-fc2895ac.js:37973:11)
at Context.resolveId (/home/kanagu/Desktop/portal/test/vite-nuxt/node_modules/vite/dist/node/chunks/dep-fc2895ac.js:37856:28)
at Object.resolveId (/home/kanagu/Desktop/portal/test/vite-nuxt/node_modules/vite/dist/node/chunks/dep-fc2895ac.js:50279:55)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async /home/kanagu/Desktop/portal/test/vite-nuxt/node_modules/vite/dist/node/chunks/dep-fc2895ac.js:74236:27
at async /home/kanagu/Desktop/portal/test/vite-nuxt/node_modules/vite/dist/node/chunks/dep-fc2895ac.js:72051:34
at async callback (/home/kanagu/Desktop/portal/test/vite-nuxt/node_modules/esbuild/lib/main.js:812:28)
at async handleRequest (/home/kanagu/Desktop/portal/test/vite-nuxt/node_modules/esbuild/lib/main.js:644:30)
node_modules/vite/dist/node/chunks/dep-fc2895ac.js:72038:18: note: This error came from the "onResolve" callback registered here
72038 โ build.onResolve({ filter: /^[\w@][^:]/ }, async ({ path: id, importer, kind, resolveDir }) => {
โต ~~~~~~~~~
at setup (/home/kanagu/Desktop/portal/test/vite-nuxt/node_modules/vite/dist/node/chunks/dep-fc2895ac.js:72038:19)
at handlePlugins (/home/kanagu/Desktop/portal/test/vite-nuxt/node_modules/esbuild/lib/main.js:736:23)
at Object.buildOrServe (/home/kanagu/Desktop/portal/test/vite-nuxt/node_modules/esbuild/lib/main.js:1024:7)
at /home/kanagu/Desktop/portal/test/vite-nuxt/node_modules/esbuild/lib/main.js:1750:17
at new Promise ()
at Object.build (/home/kanagu/Desktop/portal/test/vite-nuxt/node_modules/esbuild/lib/main.js:1749:14)
at Object.build (/home/kanagu/Desktop/portal/test/vite-nuxt/node_modules/esbuild/lib/main.js:1625:51)
at optimizeDeps (/home/kanagu/Desktop/portal/test/vite-nuxt/node_modules/vite/dist/node/chunks/dep-fc2895ac.js:72268:34)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async runOptimize (/home/kanagu/Desktop/portal/test/vite-nuxt/node_modules/vite/dist/node/chunks/dep-fc2895ac.js:72852:48)
at async Object.createServer (/home/kanagu/Desktop/portal/test/vite-nuxt/node_modules/vite/dist/node/chunks/dep-fc2895ac.js:72881:9)
at async buildClient (/home/kanagu/Desktop/portal/test/vite-nuxt/node_modules/nuxt-vite/dist/nuxt-vite.js-vite.js:106:22)
at async bundle (/home/kanagu/Desktop/portal/test/vite-nuxt/node_modules/nuxt-vite/dist/nuxt-vite.js-vite.js:459:3)
at async Builder.build (/home/kanagu/Desktop/portal/test/vite-nuxt/node_modules/@nuxt/builder/dist/builder.js:327:5)
at async Object._buildDev (/home/kanagu/Desktop/portal/test/vite-nuxt/node_modules/@nuxt/cli/dist/cli-dev.js:107:5)
node_modules/node-gyp-build/index.js:1:17: note: The plugin "vite:dep-pre-bundle" was triggered by this import
1 โ var fs = require('fs')
โต ~~~~
ERROR Build failed with 1 error: 11:31:31
node_modules/vite/dist/node/chunks/dep-fc2895ac.js:38154:14: error: [plugin: vite:dep-pre-bundle] Failed to resolve entry for package "fs". The package may have incorrect main/module/exports specified in its package.json.
node_modules/vite/dist/node/chunks/dep-fc2895ac.js:38154:14: error: [plugin: vite:dep-pre-bundle] Failed to resolve entry for package "fs". The package may have incorrect main/module/exports specified in its package.json.
at failureErrorWithLog (node_modules/esbuild/lib/main.js:1449:15)
at node_modules/esbuild/lib/main.js:1131:28
at runOnEndCallbacks (node_modules/esbuild/lib/main.js:921:63)
at buildResponseToResult (node_modules/esbuild/lib/main.js:1129:7)
at node_modules/esbuild/lib/main.js:1236:14
at node_modules/esbuild/lib/main.js:609:9
at handleIncomingPacket (node_modules/esbuild/lib/main.js:706:9)
at Socket.readFromStdout (node_modules/esbuild/lib/main.js:576:7)
at Socket.emit (events.js:315:20)
at Socket.EventEmitter.emit (domain.js:467:12)
at addChunk (internal/streams/readable.js:309:12)
at readableAddChunk (internal/streams/readable.js:284:9)
at Socket.Readable.push (internal/streams/readable.js:223:10)
at Pipe.onStreamRead (internal/stream_base_commons.js:188:23)
Any update on this issue? I experience the same thing
@lukaszarpak Could you provide a reproduction?
Close due to inactive. If it still persist, please open another issue with proper reproduction.
have the same problem.
while using this package https://www.npmjs.com/package/css
Last case for fs
, is mostly due to using incompatible (node based) library for client-side bundle, but I think since webpack4 is already stubbing built-ins, we might do the same for for vite.
I am also running into this same thing, any updates on this?
so I had this issue when requiring a mock-service-worker package which is technically isomorphic, but has a bunch of node dependencies (chokidar, node-fetch etc.)
To fix with vite:
yarn add -D rollup-plugin-node-builtins
- In your
vite.config.ts
you need to add the following (I've commented the ones I used and just left fs uncommented for this use case specifically):
resolve: {
alias: {
fs: require.resolve('rollup-pligin-node-builtins'),
// http: require.resolve('rollup-plugin-node-builtins'),
// util: require.resolve('rollup-plugin-node-builtins'),
// stream: require.resolve('rollup-plugin-node-builtins'),
// buffer: require.resolve('rollup-plugin-node-builtins'),
// process: require.resolve('rollup-plugin-node-builtins'),
// url: require.resolve('rollup-plugin-node-builtins'),
// querystring: require.resolve('rollup-plugin-node-builtins'),
},
},
- ๐ฐ
EDIT: I realise that this will probably end up being incorporated into Vite, but for those people that came from google who need a quick fix - here you go ๐
After yarn add, I wrote the settings, but I get an error.
There seems to be a problem that shebang cannot be read.
[commonjs] Unexpected character '!'
1: #!/usr/bin/env node
^
2: /**
3: * @license r.js 2.3.6 Copyright jQuery Foundation and other contributors.
I had to keep trying to build and add one by one all the node native packages that aws needs in the alias field of the vite.config.ts using the 'rollup-plugin-node-builtins' plugin , this was the result for my project to work:
resolve: {
alias: {
'.runtimeConfig': './runtimeConfig.browser',
http: require.resolve('rollup-plugin-node-builtins'),
path: require.resolve('rollup-plugin-node-builtins'),
fs: require.resolve('rollup-plugin-node-builtins'),
os: require.resolve('rollup-plugin-node-builtins'),
tslib: require.resolve('rollup-plugin-node-builtins'),
child_process: require.resolve('rollup-plugin-node-builtins'),
crypto: require.resolve('rollup-plugin-node-builtins'),
stream: require.resolve('rollup-plugin-node-builtins'),
https: require.resolve('rollup-plugin-node-builtins'),
http2: require.resolve('rollup-plugin-node-builtins'),
process: require.resolve('rollup-plugin-node-builtins'),
},
},
@jamiehaywood @MarcosMRod, what happens if require is not defined (using module not cjs)? Could be dumb question
do you have to switch to type:"commonjs
in package.json
?
Even if I use createRequre
as recommended here, I still run into issues:
thanks! fyi this is vite used to compile svelte but I think the error is still relevant.
EDIT: My bad sorry, that was because I was trying to use puppeteer (required for node chatgpt
package) on client-side. I will move it to the Node API section. Sorry again