Reputation: 287
I want to create an npm module with Nuxt 3 components. For that I defined the "nuxt.js" file the following way.
import { join } from 'path'
import { defineNuxtModule} from '@nuxt/kit'
export default defineNuxtModule({
hooks: {
'components:dirs'(dirs){
dirs.push({
path: join(__dirname, 'components'),
prefix: 'my-name'
})
}
}
})
When I publish the module and then run npm install my-module, there is no problem. I can utilize the Nuxt 3 components. However, since I want to also test if everything works as intended, I want to use npm link to test the module without publishing it.
So I execute "npm link" and then "npm link 'my-module'" in both directories. The module gets linked correctly and I can find it in my "node-modules" directory. But when running "npm run dev" I get the following error:
ERROR Cannot start nuxt: Cannot find module '@nuxt/kit' 07:39:52 Require stack: - /path/my-module/nuxt.js Require stack: - /path/my-module/nuxt.js at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15) at Function.resolve (internal/modules/cjs/helpers.js:107:19) at _resolve (node_modules/jiti/dist/jiti.js:1:108226) at jiti (node_modules/jiti/dist/jiti.js:1:110413) at /path/my-module/nuxt.js:2:12 at jiti (node_modules/jiti/dist/jiti.js:1:112282) at requireModule (node_modules/@nuxt/kit/dist/index.mjs:295:26) at normalizeModule (node_modules/@nuxt/kit/dist/index.mjs:448:53) at installModule (node_modules/@nuxt/kit/dist/index.mjs:431:47) at initNuxt (node_modules/nuxt/dist/index.mjs:1389:13)
When I try to run "npm install @nuxt/kit" it just removes "my-module" from the node-modules folder. When I then relink it, I run into the same error.
I want to test the module locally. Is there a way to fix that, and if not, is there another way to do that? (yarn link runs into the same problem)
Upvotes: 7
Views: 638