Open antfu opened 3 years ago
Kept running into this so I tried to look into it.
https://github.com/nuxt/framework/blob/33ebb01d7f0c25b5b89b767d9a0749084b0946c4/packages/kit/src/template.ts#L43
Changing this line to this if (!existsSync(template.src) && !template.getContent) {
works as a workaround for the crash/breaking on saving nuxt.config.js
. I can imagine this isn't a good way to solve the issue though.
Both middleware.js
and store.js
will cause trigger this error on save/reload, but not on startup since src
is not set yet (as seen here https://github.com/nuxt/framework/blob/main/packages/bridge/src/vite/templates.ts).
As both of these are added with addPluginTemplate
the src
will be set to their destination, and it seems like the compiled plugin template is removed on reload, which is why the error is thrown.
https://github.com/nuxt/framework/blob/33ebb01d7f0c25b5b89b767d9a0749084b0946c4/packages/kit/src/plugin.ts#L68-L80
Not sure what the intended way of fixing it is otherwise I would have opened a PR 😅.
For my dev project I added the following to the top of my nuxt.config
so I can still play around without it breaking:
const kitPath = './node_modules/@nuxt/kit/dist/index.mjs'
const kit = fs.readFileSync(kitPath, 'utf-8')
fs.writeFileSync(
kitPath,
kit.replace('if (!existsSync(template.src))', 'if (!existsSync(template.src) && !template.getContents)')
)
Environment
Darwin
v16.11.1
2.16.0-27282256.ab1c6cb4
pnpm@6.21.1
Webpack
buildModules
,css
,target
,components
,bridge
,unocss
-
Build Modules:
@unocss/nuxt@0.9.3
,@vueuse/core/nuxt@6.9.0
,@nuxt/bridge-edge@3.0.0-27283244.4a3ba73
Reproduction
(Essential every Bridge app with Vite)
https://github.com/antfu/vitesse-nuxt-bridge https://github.com/nuxt/modules
Describe the bug
Everything work until we modify the
nuxt.config.js
and triggers this error:Additional context
No response
Logs
No response