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

cannot import from nuxt/app (Package import specifier "#build/app.config.mjs" is not defined) #14801

Closed
iamdagy opened this issue Sep 5, 2022 · 38 comments

Comments

@iamdagy
Copy link

iamdagy commented Sep 5, 2022

Environment

Operating System: MacOS Ventura
Node Version: v16.13.0.
Nuxt Version: 3.0.0-rc.9
Nitro Version: 0.5.0
Package Manager: yarn@1.22.19
Builder: webpack ( I think)
User Config:
Runtime Modules:
"dependencies": {
"@formkit/i18n": "^1.0.0-beta.10",
"@pinia/nuxt": "^0.4.1",
"axios": "^0.27.2",
"pinia": "^2.0.21",
"pinia-plugin-persistedstate": "^2.1.1",
"postmark": "^3.0.1",
"swiper": "^8.3.1",
"vue3-marquee": "^3.0.7"
}
Build Modules:
"devDependencies": {
"@aceforth/nuxt-netlify": "^1.1.0",
"@formkit/nuxt": "^1.0.0-beta.11-0dd967c",
"@iconify-json/heroicons-solid": "^1.1.1",
"@nuxtjs/tailwindcss": "^5.3.2",
"@tailwindcss/typography": "^0.5.7",
"@vueuse/core": "^9.1.1",
"@vueuse/nuxt": "^9.1.1",
"netlify-cli": "^11.5.1",
"nuxt": "3.0.0-rc.9",
"unplugin-icons": "^0.14.5"
}

Reproduction

I upgrade with yarn upgrade and with yarn upgrade nuxt, then yarn upgrade --force, and then yarn upgrade --latest.
I upgraded to RC.9 and a few packages that didn't work I upgraded manually to the edge repository like formkit that needed yarn add @formkit/nuxt@next --dev .

I'will try to make a minimal reproduction, but as the project has many pages and components Im not sure if I have to recreate the whole project.

Describe the bug

When I do yarn build -> the site is completely broken it doesn't load any page.
When I do yarn dev -> the site works ok
When I do yarn check -> There is 1 error

error "@pinia/nuxt#unctx#unplugin#vite@^2.3.0" doesn't satisfy found match of "vite@3.0.9"
error Found 1 errors.

Additional context

No response

Logs

[nuxt] [request error] [unhandled] [500] Package import specifier "#build/app.config.mjs" is not defined in package /Users/david/WebstormProjects/mixverde/.output/server/node_modules/nuxt/package.json imported from /Users/david/WebstormProjects/mixverde/.output/server/node_modules/nuxt/dist/app/config.mjs
  at new NodeError (node:internal/errors:371:5)  
  at throwImportNotDefined (node:internal/modules/esm/resolve:429:9)  
  at packageImportsResolve (node:internal/modules/esm/resolve:778:3)  
  at moduleResolve (node:internal/modules/esm/resolve:924:21)  
  at defaultResolve (node:internal/modules/esm/resolve:1044:11)  
  at ESMLoader.resolve (node:internal/modules/esm/loader:422:30)  
  at ESMLoader.getModuleJob (node:internal/modules/esm/loader:222:40)  
  at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)  
  at link (node:internal/modules/esm/module_job:75:36)```
@emaia
Copy link

emaia commented Sep 5, 2022

Same to me. yarn dev works but yarn generate throw an error. My package contains:

"devDependencies": {
    "@nuxt/image": "^0.7.1",
    "@nuxtjs/tailwindcss": "^5.3.2",
    "nuxt": "3.0.0-rc.9",
    "vue-gtag-next": "^1.14.0"
  },
  "dependencies": {
    "@splidejs/vue-splide": "^0.6.7"
  }

Error log:

Nuxt 3.0.0-rc.9 with Nitro 0.5.1                                                                                                                                                             08:58:48
ℹ Using Tailwind CSS from ~/assets/css/tailwind.css                                                                                                                         nuxt:tailwindcss 08:58:57
ℹ Client built in 2815ms                                                                                                                                                                     08:59:01
ℹ Building server...                                                                                                                                                                         08:59:01
✔ Server built in 806ms                                                                                                                                                                      08:59:02
✔ Generated public .output/public                                                                                                                                                      nitro 08:59:02
ℹ Initializing prerenderer                                                                                                                                                             nitro 08:59:02
ℹ Prerendering 1 initial routes with crawler                                                                                                                                           nitro 08:59:04

 ERROR  [nuxt] [request error] [unhandled] [500] Package import specifier "#build/app.config.mjs" is not defined in package /home/.../node_modules/nuxt/package.jso
n imported from /home/.../node_modules/nuxt/dist/app/config.mjs
  at new NodeError (node:internal/errors:372:5)
  at throwImportNotDefined (node:internal/modules/esm/resolve:461:9)
  at packageImportsResolve (node:internal/modules/esm/resolve:841:3)
  at moduleResolve (node:internal/modules/esm/resolve:997:21)
  at defaultResolve (node:internal/modules/esm/resolve:1218:11)
  at ESMLoader.resolve (node:internal/modules/esm/loader:580:30)
  at ESMLoader.getModuleJob (node:internal/modules/esm/loader:294:18)
  at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:80:40)
  at link (node:internal/modules/esm/module_job:78:36)


 ERROR  [nuxt] [request error] [unhandled] [500] Package import specifier "#build/app.config.mjs" is not defined in package /home/.../node_modules/nuxt/package.jso
n imported from /home/.../node_modules/nuxt/dist/app/config.mjs
  at new NodeError (node:internal/errors:372:5)
  at throwImportNotDefined (node:internal/modules/esm/resolve:461:9)
  at packageImportsResolve (node:internal/modules/esm/resolve:841:3)
  at moduleResolve (node:internal/modules/esm/resolve:997:21)
  at defaultResolve (node:internal/modules/esm/resolve:1218:11)
  at ESMLoader.resolve (node:internal/modules/esm/loader:580:30)
  at ESMLoader.getModuleJob (node:internal/modules/esm/loader:294:18)
  at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:80:40)
  at link (node:internal/modules/esm/module_job:78:36)


 ERROR  [nuxt] [request error] [unhandled] [500] Package import specifier "#build/app.config.mjs" is not defined in package /home/.../node_modules/nuxt/package.jso
n imported from /home/.../node_modules/nuxt/dist/app/config.mjs
  at new NodeError (node:internal/errors:372:5)
  at throwImportNotDefined (node:internal/modules/esm/resolve:461:9)
  at packageImportsResolve (node:internal/modules/esm/resolve:841:3)
  at moduleResolve (node:internal/modules/esm/resolve:997:21)
  at defaultResolve (node:internal/modules/esm/resolve:1218:11)
  at ESMLoader.resolve (node:internal/modules/esm/loader:580:30)
  at ESMLoader.getModuleJob (node:internal/modules/esm/loader:294:18)
  at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:80:40)
  at link (node:internal/modules/esm/module_job:78:36)

  ├─ / (82ms) (Error: [500] Internal Server Error)                                                                                                                                     nitro 08:59:04  
✔ You can now deploy .output/public to any static hosting!

@bndrgroup
Copy link

+1 - removing vue dependency from package.json and then running the dev server works fine, however when building for production we get:

request error] [unhandled] [500] The requested module 'vue' does not provide an export named 'default'

@huang-julien
Copy link
Member

does it work if you set experimental.externalVue to false in nuxt.config ?

@iamdagy
Copy link
Author

iamdagy commented Sep 6, 2022

does it work if you set experimental.externalVue to false in nuxt.config ?

@huang-julien just tried your suggestion but the same problem continuos. Thanks for the suggestion.

@mshadowz
Copy link

mshadowz commented Sep 6, 2022

same here. im using npm and upgrading from rc8

@iamdagy iamdagy changed the title [nuxt] [request error] [unhandled] [500] in Nuxt 3.RC9 all pages unavailable in Nuxt build Nuxt 3.RC9 all pages unavailable on Nuxt build. Error [nuxt] [request error] [unhandled] [500] Sep 6, 2022
@danielroe
Copy link
Member

Please ensure you are not importing directly from nuxt/app but from #imports.

@boboldehampsink
Copy link
Contributor

Seeing the same on my end with rc9

@fatcarter
Copy link

+1 Is there a temporary solution in place?

@emaia
Copy link

emaia commented Sep 6, 2022

Please ensure you are not importing directly from nuxt/app but from #imports.

@danielroe This worked for me. thanks!

@Lyokolux
Copy link

Lyokolux commented Sep 6, 2022

I bumped my dependency and I am facing this issue with histoire.

I get:
TypeError [ERR_PACKAGE_IMPORT_NOT_DEFINED]: Package import specifier "#build/app.config.mjs" is not defined in package node_modules/nuxt/package.json imported from node_modules/nuxt/dist/app/config.mjs

The line in question is: import __appConfig from "#build/app.config.mjs";

@danielroe danielroe changed the title Nuxt 3.RC9 all pages unavailable on Nuxt build. Error [nuxt] [request error] [unhandled] [500] cannot import from nuxt/app (Package import specifier "#build/app.config.mjs" is not defined) Sep 6, 2022
@ady642
Copy link

ady642 commented Sep 6, 2022

same for me as @Lyokolux but with vitest

@boboldehampsink
Copy link
Contributor

same for me as @Lyokolux but with vitest

I fixed it by inlining nuxt as a dep

@iamdagy
Copy link
Author

iamdagy commented Sep 6, 2022

Please ensure you are not importing directly from nuxt/app but from #imports.

@danielroe what do you mean ? should I change
import { defineNuxtConfig } from 'nuxt'
to import { defineNuxtConfig } from '#imports'

or where do I make the change? how did you fixed it @emaia

@danielroe
Copy link
Member

danielroe commented Sep 6, 2022

No, your Nuxt config is the one place you should import anything from nuxt in your project.

@iamdagy
Copy link
Author

iamdagy commented Sep 6, 2022

No, your Nuxt config is the one place you should import anything from nuxt in your project.

I see, @danielroe thanks for clarifying that. I changed it in one place but the problem persist.
as far as I can see I was importing from one plugin so I changed it
from
import {defineNuxtPlugin, useCookie} from '#app'
to
import {defineNuxtPlugin, useCookie} from '#imports'

@emaia
Copy link

emaia commented Sep 6, 2022

@iamdagy I updated my code in plugins folder.

import {defineNuxtPlugin} from "#imports";

@danielroe My nuxt.config.ts was not changed and has import {defineNuxtConfig} from 'nuxt' not "#imports"

@iamdagy
Copy link
Author

iamdagy commented Sep 6, 2022

@boboldehampsink how did you add Nuxt as a dependency?
@emaia did you do this also? I have just one plugin for Pinia and did make the change to #imports but Im still seeing the same error.

Thanks

@boboldehampsink
Copy link
Contributor

I'm talking about vitest config - see https://vitest.dev/config/#deps-inline

@iamdagy
Copy link
Author

iamdagy commented Sep 6, 2022

I'm talking about vitest config - see https://vitest.dev/config/#deps-inline

@boboldehampsink I see, Im not using vitest. thanks for the info.

@iamdagy
Copy link
Author

iamdagy commented Sep 6, 2022

No, your Nuxt config is the one place you should import anything from nuxt in your project.

@danielroe can I still import from cue from pages and components? I mean thinks like ref, watch and so on?
import {nextTick, onMounted, ref, watch, watchEffect} from "vue";

I can't find any other import from Nuxt, Nuxt/app, or #app
I also tried deleting the plugin but the error persist.

The plugins is for persist state:
currently

import { createPersistedState } from 'pinia-plugin-persistedstate'
import {defineNuxtPlugin, useCookie} from '#imports'

export default defineNuxtPlugin(nuxtApp => {
    nuxtApp.$pinia.use(createPersistedState(useCookie))
})```

@Lyokolux
Copy link

Lyokolux commented Sep 7, 2022

I'm talking about vitest config - see https://vitest.dev/config/#deps-inline

Does anyone knows how to inline deps with vite such as vitest does to fix it ? I don't find it in their docs.

@iamdagy
Copy link
Author

iamdagy commented Sep 10, 2022

I was indeed importing from Nuxt/app in another place ( the Pinia Store) after changing it to #imports everything works now.

Thanks

@simllll
Copy link

simllll commented Sep 12, 2022

I'm confused, so Instead of importing from nuxt/app we have to import from "#imports".. well, it sounds strange, but okay... But if I do so, i get:
ERROR Failed to resolve import "#import" from "src/pages/index.vue". Does the file exist? (repeated 2 times) 09:18:56
Are there some special places where we have to use #imports and some where de are not alloewd to do so? Or do I miss somethign else?

Update: I wrote '#import' instead of '#imports'. Fixed it.

@simllll
Copy link

simllll commented Sep 12, 2022

And my IDE says now
image

and there is furthermore also no type inference possilbe now?

Copy link
Member

@simllll Would you raise a new issue if you can reproduce this? This is what I see...

CleanShot 2022-09-12 at 09.18.13.png

@Lyokolux
Copy link

And my IDE says now image

and there is furthermore also no type inference possilbe now?

You could run nuxi prepare to generate the .d.ts files again, or restart your TS server. Does the error still appear?

@simllll
Copy link

simllll commented Sep 13, 2022

Ah yes sorry, i figured it out already here: #14880

@poteboy
Copy link

poteboy commented Sep 16, 2022

You could run nuxi prepare to generate the .d.ts files again, or restart your TS server. Does the error still appear?

I'm still facing the same issue. replacing '#imports' w '#import' does not work either

@danielroe
Copy link
Member

This should be resolved in the edge channel, or in the next RC.

@husayt
Copy link
Contributor

husayt commented Oct 8, 2022

Still see this with Histoire

@danielroe
Copy link
Member

Then please do raise an issue there with a reproduction. Feel free to tag me.

@floriankapaun
Copy link

This still occurs to me while running tests via yarn vitest using nuxt@3.0.0-rc.11.

Inlining deps as @boboldehampsink mentioned didn't do the trick for me.

My Error still remains:

TypeError: Package import specifier "#build/app.config.mjs" is not defined in package /Users/.../app/node_modules/nuxt/package.json imported from /Users/.../app/node_modules/nuxt/dist/app/config.mjs

After tracking it further down, it seems like the error occurs only if import { useRuntimeConfig } from '#imports' is used. But according to previous comments, this should work, no @danielroe?

Copy link
Member

Yes, this should work, assuming you are using nuxt/test-utils and not unit testing that component. (Follow https://github.com/nuxt/nuxt.js/issues/13077 for unit testing support.)

@ChurikiTenna
Copy link

I am experiencing the same issue.
Using rc12.

replacing nuxt/app with #imports removed the error, instead, caused this new error:
Cannot find module '#imports' or its corresponding type declarations.
Editing tsconfig according to #14880 didn't resolve my case.

@danielroe
Copy link
Member

@ChurikiTenna Would you open a new issue with a reproduction?

@MikeAltinget
Copy link

@ChurikiTenna Would you open a new issue with a reproduction?

I have a similar issue and have created an issue with reproduction over here: histoire-dev/histoire#430

@danielroe
Copy link
Member

danielroe commented Jan 24, 2023

That isn't a Nuxt issue but to do with the way histoire is loading nuxt composables outside the Nuxt environment. We're tracking improvements that third-party tools can take advantage of via:

@BBoehm
Copy link

BBoehm commented Jun 6, 2023

We also experienced this issue with histoire (v 0.12.4) and useCookie. Upgrading to v 0.15 fixed the issue, but caused some other problems, so we had to find another solution.

Relied on an external package in the end, since we did not find a better solution
import { useCookie } from '@vue-composable/cookie';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests