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

Server failed when reloading nuxt.config.js with Bridge Vite #47

Open
antfu opened this issue Nov 16, 2021 · 1 comment
Open

Server failed when reloading nuxt.config.js with Bridge Vite #47

antfu opened this issue Nov 16, 2021 · 1 comment
Assignees
Labels
bug Something isn't working vite

Comments

@antfu
Copy link
Member

antfu commented Nov 16, 2021

Environment



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:

 FATAL  Template not found: /Users/antfu/i/vitesse-nuxt-bridge/.nuxt/middleware.js                10:01:04

  at normalizeTemplate (node_modules/.pnpm/@[email protected]/node_modules/@nuxt/kit-edge/dist/index.mjs:924:13)
  at addTemplate (node_modules/.pnpm/@[email protected]/node_modules/@nuxt/kit-edge/dist/index.mjs:908:20)
  at addPluginTemplate (node_modules/.pnpm/@[email protected]/node_modules/@nuxt/kit-edge/dist/index.mjs:973:16)
  at setup (node_modules/.pnpm/@[email protected]/node_modules/@nuxt/bridge-edge/dist/chunks/module2.mjs:152:5)
  at Object.wrappedModule (node_modules/.pnpm/@[email protected]/node_modules/@nuxt/kit-edge/dist/index.mjs:1212:22)
  at installModule (node_modules/.pnpm/@[email protected]/node_modules/@nuxt/kit-edge/dist/index.mjs:1261:17)
  at setup (node_modules/.pnpm/@[email protected]/node_modules/@nuxt/bridge-edge/dist/chunks/module.mjs:993:13)
  at async ModuleContainer.addModule (node_modules/.pnpm/@[email protected]/node_modules/@nuxt/core-edge/dist/core.js:174:20)
  at async ModuleContainer.ready (node_modules/.pnpm/@[email protected]/node_modules/@nuxt/core-edge/dist/core.js:45:7)
  at async Nuxt._init (node_modules/.pnpm/@[email protected]/node_modules/@nuxt/core-edge/dist/core.js:346:5)


 ERROR  Cannot restart nuxt:  Template not found: /Users/antfu/i/vitesse-nuxt-bridge/.nuxt/middleware.js

  at normalizeTemplate (node_modules/.pnpm/@[email protected]/node_modules/@nuxt/kit-edge/dist/index.mjs:924:13)
  at addTemplate (node_modules/.pnpm/@[email protected]/node_modules/@nuxt/kit-edge/dist/index.mjs:908:20)
  at addPluginTemplate (node_modules/.pnpm/@[email protected]/node_modules/@nuxt/kit-edge/dist/index.mjs:973:16)
  at setup (node_modules/.pnpm/@[email protected]/node_modules/@nuxt/bridge-edge/dist/chunks/module2.mjs:152:5)
  at Object.wrappedModule (node_modules/.pnpm/@[email protected]/node_modules/@nuxt/kit-edge/dist/index.mjs:1212:22)
  at installModule (node_modules/.pnpm/@[email protected]/node_modules/@nuxt/kit-edge/dist/index.mjs:1261:17)
  at setup (node_modules/.pnpm/@[email protected]/node_modules/@nuxt/bridge-edge/dist/chunks/module.mjs:993:13)
  at async ModuleContainer.addModule (node_modules/.pnpm/@[email protected]/node_modules/@nuxt/core-edge/dist/core.js:174:20)
  at async ModuleContainer.ready (node_modules/.pnpm/@[email protected]/node_modules/@nuxt/core-edge/dist/core.js:45:7)
  at async Nuxt._init (node_modules/.pnpm/@[email protected]/node_modules/@nuxt/core-edge/dist/core.js:346:5)


 ERROR  [unhandledRejection] ENOENT: no such file or directory, open '/Users/antfu/i/vitesse-nuxt-bridge/.nuxt/dist/server/client.manifest.json'

Additional context

No response

Logs

No response

@antfu antfu self-assigned this Nov 16, 2021
@danielroe danielroe added bug Something isn't working vite and removed pending triage labels Nov 16, 2021
@BobbieGoede
Copy link
Member

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.

https://github.com/nuxt/framework/blob/33ebb01d7f0c25b5b89b767d9a0749084b0946c4/packages/kit/src/template.ts#L41-L55

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)')
)

@danielroe danielroe transferred this issue from nuxt/framework Apr 13, 2022
@danielroe danielroe removed the bridge label Apr 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working vite
Projects
None yet
Development

No branches or pull requests

3 participants