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

Could not resolve import "#app" #242

Closed
trandaison opened this issue Mar 19, 2024 · 2 comments
Closed

Could not resolve import "#app" #242

trandaison opened this issue Mar 19, 2024 · 2 comments

Comments

@trandaison
Copy link

I created a module https://github.com/trandaison/nuxt-3-auth, the playground is working perfectly.
However, when I run npm run prepack, I got this error

(node-resolve plugin) Could not resolve import "#app" in /nuxt-3-auth/src/runtime/services/AuthStorage.ts using imports defined in /nuxt-3-auth/package.json.
(node-resolve plugin) Could not resolve import "#app" in /nuxt-3-auth/src/runtime/services/AuthStorage.ts using imports defined in /nuxt-3-auth/package.json.
"#app" is imported by "src/runtime/services/AuthStorage.ts", but could not be resolved – treating it as an external dependency.

 WARN  Build is done with some warnings:
- Inlined implicit external #app

 ERROR  Exiting with code (1). You can change this behavior by setting failOnWarn: false . 

Screenshot 2024-03-19 at 11 17 13

Since AuthStorage.ts is not using any import from #app anymore, I don't know why it still throws this error.

=====

  • Operating System: Darwin
  • Node Version: v18.16.0
  • Nuxt Version: 3.8.2
  • CLI Version: 3.9.1
  • Nitro Version: 2.8.1
  • Package Manager: pnpm@8.15.0
  • Builder: -
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -
@trandaison
Copy link
Author

My workaround is set failOnWarn: false by create a build.config.ts

import { defineBuildConfig } from "unbuild";

export default defineBuildConfig({
  failOnWarn: false,
});

However, I think this is a bug, should be fixed in the module builder itself, and the docs should show an example how to custom the build config as well.

@danielroe
Copy link
Member

The reason this is happening is that your module is importing types from the runtime code, which itself is augmenting #app.

Instead, you should likely extract your types into a location where they can be shared between your runtime and build-time code.

If you do add config, it should likely be to add #app to your externals, like this:

import { defineBuildConfig } from "unbuild"

export default defineBuildConfig({
  externals: ['#imports', '#app'],
})

We may be able to improve this experience as having shared types between build/runtime is often necessary.

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

No branches or pull requests

2 participants