Environment
- Operating System:
Linux
- Node Version:
v16.11.1
- Nuxt Version:
3.0.0-rc.3
- Package Manager:
[email protected]
- Builder:
vite
- User Config:
-
- Runtime Modules:
-
- Build Modules:
-
Reproduction
npx nuxi init nuxt-app \
cd nuxt-app \
yarn install \
yarn add ipfs-core \
mkdir pages plugins \
nuxt-app/app.vue
; replace NuxtWelcome with NuxtPage
nuxt-app/pages/index.vue
; This is just here to enable the router(the following plugins file wouldn't work without router enabled). Just a vanilla template, no script, maybe a p tag or something
nuxt-app/plugins/ipfs.ts
; looks like this
`
import {create} from 'ipfs-core'
export default defineNuxtPlugin(() => {
return {
provide: {
ipfs: () => create()
}
}
})
`
yarn dev -o
Describe the bug
Without using the plugin anywhere, just importing the module and creating the js-ipfs node triggers a weird loop. The following happens if implemented with pinia instead of using a plugin as well. To avoid the loop and just see the single error skip the -o
in yarn dev
.
Output:
โ [ERROR] Could not resolve "electron"
node_modules/electron-fetch/lib/index.es.js:1257:21:
1257 โ electron = require('electron');
โต ~~~~~~~~~~
You can mark the path "electron" as external to exclude it from the bundle, which will remove this
error. You can also surround this "require" call with a try/catch block to handle this failure at
run-time instead of bundle-time.
ERROR 4:40:05 PM [vite] error while updating dependencies: 16:40:05
Error: Build failed with 1 error:
node_modules/electron-fetch/lib/index.es.js:1257:21: ERROR: Could not resolve "electron"
at failureErrorWithLog (/home/foss/gits/nuxt-app/node_modules/esbuild/lib/main.js:1603:15)
at /home/foss/gits/nuxt-app/node_modules/esbuild/lib/main.js:1249:28
at runOnEndCallbacks (/home/foss/gits/nuxt-app/node_modules/esbuild/lib/main.js:1034:63)
at buildResponseToResult (/home/foss/gits/nuxt-app/node_modules/esbuild/lib/main.js:1247:7)
at /home/foss/gits/nuxt-app/node_modules/esbuild/lib/main.js:1356:14
at /home/foss/gits/nuxt-app/node_modules/esbuild/lib/main.js:666:9
at handleIncomingPacket (/home/foss/gits/nuxt-app/node_modules/esbuild/lib/main.js:763:9)
at Socket.readFromStdout (/home/foss/gits/nuxt-app/node_modules/esbuild/lib/main.js:632:7)
at Socket.emit (node:events:390:28)
at Socket.emit (node:domain:475:12)
ERROR Vite Error, /_nuxt/node_modules/.vite/deps/ipfs-core.js?v=0a934655 optimized info should be defined 16:40:05
If I try doing yarn add electron
(which I don't think I need) the following happens with more messages saying"optimized info should be defined" for other deps;
โ [ERROR] No matching export in "browser-external:url" for import "parse"
node_modules/electron-fetch/lib/index.es.js:1:9:
1 โ import { parse, format, resolve } from 'url';
โต ~~~~~
โ [ERROR] No matching export in "browser-external:url" for import "format"
node_modules/electron-fetch/lib/index.es.js:1:16:
1 โ import { parse, format, resolve } from 'url';
โต ~~~~~~
โ [ERROR] No matching export in "browser-external:url" for import "resolve"
node_modules/electron-fetch/lib/index.es.js:1:24:
1 โ import { parse, format, resolve } from 'url';
โต ~~~~~~~
โ [ERROR] No matching export in "browser-external:http" for import "STATUS_CODES"
node_modules/electron-fetch/lib/index.es.js:3:9:
3 โ import { STATUS_CODES } from 'http';
โต ~~~~~~~~~~~~
โ [ERROR] No matching export in "browser-external:stream" for import "PassThrough"
node_modules/electron-fetch/lib/index.es.js:6:17:
6 โ import Stream, { PassThrough } from 'stream';
โต ~~~~~~~~~~~
Additional context
I've also tried disabling Vite for Webpack5 with no luck, that produces a different set of errors, besides I'd like to get this working in Vite.
I've taken a look at this repository but also had no luck; https://github.com/DougAnderson444/ipfs-vite-svelte-kit
Can provide more info on why that failed if requested. I thought Vite used esbuild under the hood anyway so I'm not sure why that repo was even needed to adapt ipfs-core for vite.
I've previously built projects with Nuxt2 using ipfs-core in the 2020-2021 without issue. Pretty sure this because I'm using all fairly new tooling and RC builds of those tools, but if anyone has any insight into why this may be happening I would greatly appreciate it.
Logs
No response