(My English is weak, the following text is translated by Deepl) In the process of learning this framework by reading the Nuxt3 documentation, when I read the following section
https://nuxt.com/docs/getting-started/views#advanced-extending-the-html-template
I encountered a problem in the code practice, I created the following file '~/server/plugins/extend-html.ts'
import {nitroApp} from "nitropack/dist/runtime/app";
export default defineNitroPlugin((nitro) => {
nitroApp.hooks.hook('render:html',(html,{ event }) => {
console.log(html)
console.log(event)
html.head.push('<meta name="test" content="test">')
})
nitroApp.hooks.hook('render:response',(response,{ event }) => {
console.log(response)
})
})
and added in nuxt.config.ts as per the documentation.
nitro:{
plugins:[
'~/server/plugins/extend-html.ts',
]
}
But there is an error
[17:11:34] ERROR [worker reload] [worker init] Package import specifier "#internal/nitro/virtual/plugins" is not defined in package D:\\WebStormProject\\Nuxt-test\\node_modules\\nitropack\\package.json imported from D:\\WebStormProj
ect\\Nuxt-test\\node_modules\\nitropack\\dist\\runtime\\app.mjs
at __node_internal_captureLargerStackTrace (node:internal/errors:490:5)
at new NodeError (node:internal/errors:399:5)
at importNotDefined (node:internal/modules/esm/resolve:350:10)
at packageImportsResolve (node:internal/modules/esm/resolve:777:9)
at moduleResolve (node:internal/modules/esm/resolve:932:16)
at defaultResolve (node:internal/modules/esm/resolve:1153:11)
at nextResolve (node:internal/modules/esm/loader:163:28)
at ESMLoader.resolve (node:internal/modules/esm/loader:838:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40)
at link (node:internal/modules/esm/module_job:76:36)
I have tried the following for this bug
-
Delete node_modelus to rebuild the project ×
-
Update nitropack to the latest version ×
-
Restarting the project ×
I hope you can give me some help, thanks a million! (tip:When I remove extend-html.ts and its related content in the project, the project works fine