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 start nuxt: Package subpath './nuxt' is not defined by "exports" #14602

Closed
jclaessens97 opened this issue Aug 16, 2022 · 8 comments
Closed

Comments

@jclaessens97
Copy link

jclaessens97 commented Aug 16, 2022

I setup a nuxt module following the (limited) docs and the module starter template.

The playground works, but whenever I want to build and use it in my main nuxt application (using pnpm and file:../ui), I get following error output:

Nuxt CLI v3.0.0-rc.8                                                  09:15:59
                                                                      09:16:02
  > Local:    http://localhost:8080/
  > Network:  http://10.11.12.43:8080/


 ERROR  Cannot start nuxt:  Package subpath './nuxt' is not defined by "exports" in /Users/jclaessens/dev/proj/packages/nuxt3_web/node_modules/@skyebase/ui/package.json

  at new NodeError (node:internal/errors:371:5)
  at throwExportsNotFound (node:internal/modules/esm/resolve:453:9)
  at packageExportsResolve (node:internal/modules/esm/resolve:729:3)
  at resolveExports (node:internal/modules/cjs/loader:482:36)
  at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
  at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
  at Function.resolve (node:internal/modules/cjs/helpers:108:19)
  at Function._resolve [as resolve] (/Users/jclaessens/dev/proj/node_modules/.pnpm/jiti@1.14.0/node_modules/jiti/dist/jiti.js:1:108226)
  at resolveModule (/Users/jclaessens/dev/proj/node_modules/.pnpm/@nuxt+kit@3.0.0-rc.8_webpack@5.74.0/node_modules/@nuxt/kit/dist/index.mjs:253:29)
  at normalizeModule (/Users/jclaessens/dev/proj/node_modules/.pnpm/@nuxt+kit@3.0.0-rc.8_webpack@5.74.0/node_modules/@nuxt/kit/dist/index.mjs:462:18)

npx nuxi info output:

❯ npx nuxi info
Nuxt CLI v3.0.0-rc.8                                                                                                                                                                  09:30:16
RootDir: /Users/jclaessens/dev/proj/packages/nuxt3_web                                                                                                                    09:30:18
Nuxt project info:                                                                                                                                                                    09:30:18

------------------------------
- Operating System: `Darwin`
- Node Version:     `v16.14.0`
- Nuxt Version:     `3.0.0-rc.8`
- Package Manager:  `pnpm@7.9.0`
- Builder:          `vite`
- User Config:      `ssr`, `typescript`, `css`, `modules`, `runtimeConfig`
- Runtime Modules:  `@vueuse/nuxt@8.9.4`, `proj/nuxt@1.0.0`
- Build Modules:    `-`
------------------------------

👉 Report an issue: https://github.com/nuxt/framework/issues/new                                                                                                                      09:30:18

👉 Suggest an improvement: https://github.com/nuxt/framework/discussions/new

👉 Read documentation: https://v3.nuxtjs.org

I configured the module as proj/ui/nuxt and I'm sure I build it first using the prepack command.

Any pointers on what it could be?

(I replaced the real namespaced project name with proj)

@danielroe
Copy link
Member

Impossible to say exactly without seeing your code, but you likely need to add a subpath exports like:

  "exports": {
    // ...
    "./nuxt": "./dist/nuxt.mjs"
  },

See more at https://nodejs.org/api/packages.html#packages_subpath_exports.

@jclaessens97
Copy link
Author

jclaessens97 commented Aug 16, 2022

Thanks for your answer.
I can try to make a minimal repro later today if it's something that hasn't come up yet...

As for the exports I just used the "main" and direct it to the built module files:

"type": "module",
  "exports": {
    ".": {
      "import": "./dist/module.mjs",
      "require": "./dist/module.cjs"
    }
  },
  "main": "./dist/module.cjs",
  "types": "./dist/types.d.ts",
  "files": [
    "dist"
  ],

My module.ts looks like this:

import {
  defineNuxtModule,
  addComponentsDir,
  addPlugin,
  createResolver,
} from '@nuxt/kit';

export default defineNuxtModule({
  meta: {
    name: 'proj/ui',
    compatibility: {
      nuxt: '^3.0.0',
    },
  },
  setup(options, nuxt) {
    const { resolve } = createResolver(import.meta.url);

    nuxt.options.css = [
      'primevue/resources/themes/md-light-deeppurple/theme.css',
      'primevue/resources/primevue.min.css',
      'primeicons/primeicons.css',
      'primeflex/primeflex.css',
      ...nuxt.options.css,
    ];
    nuxt.options.build.transpile.push('primevue');

    const pluginDir = resolve(__dirname, 'runtime', 'plugins');
    addPlugin(resolve(pluginDir, 'vue-country-flag.plugin.ts'));
    addPlugin(resolve(pluginDir, 'mapbox.plugin.ts'));
    addPlugin(resolve(pluginDir, 'primevue.plugin.ts'));
    addPlugin(resolve(pluginDir, 'primevue.plugin.client.ts'));

    addComponentsDir({
      path: resolve(__dirname, 'runtime', 'components'),
      prefix: 'sb',
    });
  },
});

And then runtime contains just plugins and components using primevue as plain vue/nuxt code.

If you still need more info to investigate, please let me know then I'll try to setup a minimal repro.

@danielroe
Copy link
Member

Yes, a reproduction would be helpful, thanks.

@danielroe danielroe transferred this issue from nuxt/starter Aug 16, 2022
@jclaessens97
Copy link
Author

Added a repro on my personal github in the following repository: https://github.com/jclaessens97/nuxt-module-repro

@danielroe
Copy link
Member

Yes, if you are importing from @proj/ui/nuxt you need a subpath export: #14602

But you don't need it. Just remove the /nuxt suffix and you should be good to go:

-   modules: ['@proj/ui/nuxt'],
+   modules: ['@proj/ui'],

@danielroe danielroe closed this as not planned Won't fix, can't repro, duplicate, stale Sep 20, 2022
@jclaessens97
Copy link
Author

jclaessens97 commented Sep 28, 2022

In the same repro I tried removing the /nuxt suffix, but then another (related?) error arises:

Failed to resolve import "/Users/jclaessens/dev/github/nuxt-module-repro/node_modules/.pnpm/file+packages+lib+ui_ufy6fydyuyaiiyys52pg2bdj2m/node_modules/@proj/ui/dist/runtime/plugins/primevue.plugin.client.ts" from "virtual:nuxt:/Users/jclaessens/dev/github/nuxt-module-repro/packages/nuxt-app/.nuxt/plugins/client.mjs". Does the file exist?

It's not only the primevue plugin. I have the same with all plugins. It always throws on the first plugin I try to add (bottom to top in the module.ts file).

@danielroe
Copy link
Member

danielroe commented Sep 28, 2022

Great! (in response to a message that read: "And now it seems to be working fine 👌")

@jclaessens97
Copy link
Author

jclaessens97 commented Sep 28, 2022

Great! (in response to a message that read: "And now it seems to be working fine 👌")

Yeah, my bad, I removed it since I was a bit too quick 😅

I managed to get it working, but there is still something off.

For the repro to work, I have to run dev:prepare before prepack, and then install it in the main app, so not sure if this is intended behavior or not. If it is, then it's working correctly I suppose..

I'm still investigating though because in my real app it's still not working.

@danielroe danielroe added the 3.x label Jan 19, 2023
@danielroe danielroe transferred this issue from nuxt/framework Jan 19, 2023
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

2 participants