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

Error with Nuxt v3.0.0-rc.9: Package import specifier "#build/app.config.mjs" is not defined in package #286

Closed
6 tasks done
ghost opened this issue Sep 11, 2022 · 19 comments
Labels
nuxt to triage This issue needs to be triaged

Comments

@ghost
Copy link

ghost commented Sep 11, 2022

Describe the bug

When using Histoire with Nuxt v3.0.0-rc.9 there seems to be an issue with the built-in components like <NuxtLink>. (Nuxt v3.0.0-rc.8 works fine)

  1. Visit reproduction link
  2. run npm run dev - everything should work fine.
  3. Uncomment the <NuxtLink> in the BaseButton.vue component and reload webcontainer.

Error occurs:
Error while collecting story /home/projects/nuxt-starter-sf9sq6/stories/BaseButton.story.vue:
TypeError [ERR_PACKAGE_IMPORT_NOT_DEFINED]: Package import specifier "#build/app.config.mjs" is not defined in package /home/projects/nuxt-starter-sf9sq6/node_modules/nuxt/package.json imported from /home/projects/nuxt-starter-sf9sq6/node_modules/nuxt/dist/app/config.mjs

There is also an issue in the Nuxt repo regarding this issue: nuxt/nuxt#14801

Reproduction

https://stackblitz.com/edit/nuxt-starter-sf9sq6?file=components/BaseButton.vue

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (4) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.14.2 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 7.17.0 - /usr/local/bin/npm
  npmPackages:
    @histoire/plugin-nuxt: ^0.10.7 => 0.10.7 
    @histoire/plugin-vue: ^0.10.7 => 0.10.7 
    histoire: ^0.10.7 => 0.10.7

Used Package Manager

npm

Validations

@ghost ghost added the to triage This issue needs to be triaged label Sep 11, 2022
@Lyokolux
Copy link
Contributor

Lyokolux commented Sep 15, 2022

I have the issue with a .story.vue file too. It happens on RC-9 and RC-10.

Error while collecting story components/molecules/PwLinkInput.story.vue:
TypeError [ERR_PACKAGE_IMPORT_NOT_DEFINED]: Package import specifier "#build/app.config.mjs" is not defined in node_modules/nuxt/package.json imported from 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)

@Akryum Akryum added the nuxt label Sep 17, 2022
@danielroe
Copy link
Collaborator

danielroe commented Sep 20, 2022

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

Repro

Let me know if not.

@ghost
Copy link
Author

ghost commented Sep 20, 2022

Hmm no, still the same error, tested on Stackblitz (but I am not able to get the latest edge release, it still states it is rc.9)

And locally with edge release, still same error message with reference to rc.11

Error while collecting story /home/gmavors/dev/nue/stories/BaseIcon.story.vue:
TypeError [ERR_PACKAGE_IMPORT_NOT_DEFINED]: Package import specifier "#build/app.config.mjs" is not defined in package /home/gmavors/dev/nue/node_modules/.pnpm/nuxt3@3.0.0-rc.11-27727864.720da64_itqs5654cmlnjraw6gjzqacppi/node_modules/nuxt3/package.json imported from /home/gmavors/dev/nue/node_modules/.pnpm/nuxt3@3.0.0-rc.11-27727864.720da64_itqs5654cmlnjraw6gjzqacppi/node_modules/nuxt3/dist/app/config.mjs
    at new NodeError (node:internal/errors:372:5)
    at throwImportNotDefined (node:internal/modules/esm/resolve:422:9)
    at packageImportsResolve (node:internal/modules/esm/resolve:791:3)
    at moduleResolve (node:internal/modules/esm/resolve:944:16)
    at defaultResolve (node:internal/modules/esm/resolve:1166:11)
    at ESMLoader.resolve (node:internal/modules/esm/loader:536:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:250:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:79:40)
    at link (node:internal/modules/esm/module_job:78:36)

@danielroe
Copy link
Collaborator

You should be able to see it working in the stackblitz I linked.

@ghost
Copy link
Author

ghost commented Sep 20, 2022

The BaseButton.vue component has a <NuxtLink> inside which is commented out, if I uncomment the <NuxtLink>, I still get the error.

@saschafuchs
Copy link

I have the problem too. In my case (current Nuxt 3 RC11) the error occurs when the component has a Pinia store included or I use useRoute(). <NuxtLink> works without problems.

@zoey-kaiser
Copy link

I have the problem too. In my case (current Nuxt 3 RC11) the error occurs when the component has a Pinia store included or I use useRoute(). <NuxtLink> works without problems.

Same issue here: sidebase/sidebase#51

@danielroe
Copy link
Collaborator

If you are experiencing this error (with 'import specifier' error message), would you provide a reproduction? I cannot reproduce it.

As for the issue with NuxtLink in the sandbox above:

  1. You did not define any to prop so <NuxtLink v-if="to" :to="to" class="button"><slot /></NuxtLink> would always fail to render and would likely also error.
  2. <NuxtLink> depends on having nuxt context available so you likely need to stub this out in your project.

@ghost
Copy link
Author

ghost commented Oct 2, 2022

Regarding the missing props, you were right. But when I use rc.8, I can use <NuxtLink>, with rc.11, an error occurs.

TypeError: Cannot read properties of undefined (reading '_observer') at useObserver (nuxt-link.mjs?v=8c5a6940:204:15) at setup (nuxt-link.mjs?v=8c5a6940:126:28) at callWithErrorHandling (runtime-core.esm-bundler.js:155:22) at setupStatefulComponent (runtime-core.esm-bundler.js:7187:29) at setupComponent (runtime-core.esm-bundler.js:7142:11) at mountComponent (runtime-core.esm-bundler.js:5491:13) at processComponent (runtime-core.esm-bundler.js:5466:17) at patch (runtime-core.esm-bundler.js:5068:21) at mountChildren (runtime-core.esm-bundler.js:5252:13) at processFragment (runtime-core.esm-bundler.js:5425:13)

So this should most likely be fixed in the @histoire/plugin-nuxt package or not?

@danielroe
Copy link
Collaborator

The change is that now, in nuxt core, <NuxtLink> depends on useNuxtApp() (in order to observe + prefetch links - nuxt/framework#4329).

We are exploring ideas in Nuxt to make this easier to integrate with tools like Histoire, but until then you'll need to stub NuxtLink.

It's not a bug with Histoire; there are quite a lot of Nuxt core composables or components that depend on a broader Nuxt context. But possibly we could provide some built-in stubs in histoire - what do you think @Akryum?

@tobiashm
Copy link

I'm still getting this error with Nuxt 3.0.0-rc.11 and Histoire 0.11.3 :(

Error while collecting story /…/Something.story.vue:
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
    at new NodeError (node:internal/errors:393:5)
    at throwImportNotDefined (node:internal/modules/esm/resolve:329:9)
    at packageImportsResolve (node:internal/modules/esm/resolve:698:3)
    at moduleResolve (node:internal/modules/esm/resolve:853:16)
    at defaultResolve (node:internal/modules/esm/resolve:1074: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:425:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)
    at link (node:internal/modules/esm/module_job:75:36)

Seems like something the Nuxt plug-in ought to take care of?

Copy link
Collaborator

@tobiashm A reproduction would be appreciated.

@tobiashm
Copy link

@danielroe I will try to isolate the issue. It appears that about 1/5 of our stories are not affected by this, but I can't see what's different about the components in the ones that seems to work.

@Lyokolux
Copy link
Contributor

Lyokolux commented Oct 12, 2022

I'm still getting this error with Nuxt 3.0.0-rc.11 and Histoire 0.11.3 :(

Error while collecting story /…/Something.story.vue:
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
    at new NodeError (node:internal/errors:393:5)
    at throwImportNotDefined (node:internal/modules/esm/resolve:329:9)
    at packageImportsResolve (node:internal/modules/esm/resolve:698:3)
    at moduleResolve (node:internal/modules/esm/resolve:853:16)
    at defaultResolve (node:internal/modules/esm/resolve:1074: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:425:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)
    at link (node:internal/modules/esm/module_job:75:36)

Seems like something the Nuxt plug-in ought to take care of?

Here some content: It fails on 2 stories out of 50 for me. Both stories uses a common Vue Component.
I replaced the line with the useFetch in this component and it works:

// const { data } = await useFetch(`/api/v1/links/generate/${cleanedValue}`, { key: new Date().toISOString() })
const data = ref()

Copy link
Collaborator

Yes, useFetch relies on the nuxt context. Surely this didn't ever work in histoire?

@Lyokolux
Copy link
Contributor

Lyokolux commented Oct 12, 2022

Yes, useFetch relies on the nuxt context. Surely this didn't ever work in histoire?

It works with Nuxt RC.8 and Histoire 0.10.7. They are my current working versions.

@ghost
Copy link
Author

ghost commented Oct 12, 2022

As stated in the initial post of this issue, something changed in Nuxt RC.9 because stories with NuxtLink in it were working in Histoire with Nuxt RC.8.

I've now again an issue when using the Nuxt Icon Module since it also relies on the nuxt context, it is not working with Histoire and I again get these errors "package import specifier....". Also I am not able to go back to RC.8 because the module needs atleast RC.9.

We are exploring ideas in Nuxt to make this easier to integrate with tools like Histoire, but until then you'll need to stub NuxtLink.

It's not a bug with Histoire; there are quite a lot of Nuxt core composables or components that depend on a broader Nuxt context. But possibly we could provide some built-in stubs in histoire - what do you think @Akryum?

So until this is not resolved, we would need create workarounds for all components which rely directly on the nuxt context or use components which rely on it?

@T-Zahil
Copy link

T-Zahil commented Dec 20, 2022

Same issue for me when importing a component using the <Icon> from Nuxt Icon Module

@david8z
Copy link

david8z commented Jan 8, 2023

Why is this closed if it is still happening?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
nuxt to triage This issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

8 participants