nuxt / module-builder

Complete solution to build and ship Nuxt modules.
MIT License
211 stars 22 forks source link

`Could not map moduleDetection force` when running npm run prepack #297

Closed fornazaric closed 4 days ago

fornazaric commented 1 week ago

Hello,

I've been running @nuxt/module-builder in version 0.5.5 for some time now, but when i tried updating to 0.8.0 the error written later popped up. I'm now upgrading to 0.6.0 only and face the same issue

I already tried:

Here's the error:

Could not map moduleDetection force

[2:44:11 PM]  ERROR  module is a string value; tsconfig JSON must be parsed with parseJsonSourceFileConfigFileContent or getParsedCommandLineOfConfigFile before passing to createProgram

  at createProgram (node_modules/typescript/lib/typescript.js:123997:15)
  at synchronizeHostDataWorker (node_modules/typescript/lib/typescript.js:148933:15)
  at synchronizeHostData (node_modules/typescript/lib/typescript.js:148829:7)
  at Object.getProgram (node_modules/typescript/lib/typescript.js:149005:5)
  at getProgram (node_modules/@volar/typescript/lib/getProgram.js:34:19)
  at Object.set (node_modules/@volar/typescript/lib/getProgram.js:28:29)
  at Object.createProgram (node_modules/vue-tsc/out/index.js:61:23)
  at emitVueTscV1 (node_modules/mkdist/dist/index.mjs:394:28)
  at async getVueDeclarations (node_modules/mkdist/dist/index.mjs:358:7)
  at async mkdist (node_modules/mkdist/dist/index.mjs:526:35)

[2:44:11 PM]  ERROR  module is a string value; tsconfig JSON must be parsed with parseJsonSourceFileConfigFileContent or getParsedCommandLineOfConfigFile before passing to createProgram

I tried changing my tsconfig, resetting it to the one in the starter app, but nothing changes.

I think the problem might come from the module definition file:

  import {
      addComponentsDir,
      createResolver,
      defineNuxtModule,
      installModule
  } from '@nuxt/kit'
  import type { ModuleOptions } from '@nuxt/schema'

  export default defineNuxtModule<ModuleOptions>({
      meta: {
          name: 'redacted',
          configKey: 'redacted'
      },
      // Default configuration options of the Nuxt module
      defaults: {},
      async setup(_options, nuxt) {
          const resolver = createResolver(import.meta.url)
          nuxt.options.build.transpile.push(resolver.resolve('./runtime'))

          nuxt.hook('nitro:config', async (nitroConfig) => {
              nitroConfig.publicAssets ||= []
              nitroConfig.publicAssets.push({
                  dir: resolver.resolve('./runtime/public'),
                  maxAge: 60 * 60 * 24 * 365 // 1 year
              })
          })

          nuxt.options.alias['#redacted/types'] =
              resolver.resolve('runtime/interfaces')

          nuxt.options.alias['#redacted/utils'] = resolver.resolve(
              'runtime/utils/shared'
          )

          const componentsPaths = [
              resolver.resolve('runtime/components/common/global'),
          ]

          componentsPaths.forEach((path) => {
              addComponentsDir({
                  path,
                  global: true
              })
          })

          await installModule('@nuxtjs/tailwindcss', {
              // module configuration
              exposeConfig: true,
              config: {
                  content: {
                      files: [
                          resolver.resolve('./runtime/**/*.{vue,mjs,ts}'),
                          resolver.resolve('./runtime/*.{mjs,js,ts}')
                      ]
                  }
              }
          })

          await installModule('@nuxtjs/i18n', {
              vueI18n: resolver.resolve('./i18nconfig')
          })

          await installModule('@nuxtjs/device', {})
      }
  })

I also have a tsconfig file for the playground and one for the tests folder that use vitest.

Here's the main tsconfig file:


{
  "extends": "./.nuxt/tsconfig.json",
  "compilerOptions": {
    "types": ["vitest/globals"]
  },
  "exclude": [
    "dist",
    "node_modules",
    "playground",
    "test"
  ]
}

Thanks for your help !

HugoRCD commented 1 week ago

Got the exact same issue in this repository: https://github.com/Mockline/mockline/tree/mk-90

vernaillen commented 1 week ago

Same error here after upgrading typescript to 5.5.2. The error went away after downgrading typescript to 5.4.5

HugoRCD commented 1 week ago

This allows the command to be run successfully, but the 'Could not map moduleDetection force is always the same

fornazaric commented 5 days ago

I just tried downgrading Typescript and now i have this error:


 ERROR  VirtualCode id must be lowercase: scriptFormat              

  at verifyVirtualCode (node_modules/@volar/language-core/index.js:230:19)
  at Object.set (node_modules/@volar/language-core/index.js:127:29)
  at node_modules/@volar/typescript/lib/node/proxyCreateProgram.js:76:42
  at Object.get (node_modules/@volar/language-core/index.js:42:17)
  at options.host.getSourceFile (node_modules/@volar/typescript/lib/node/proxyCreateProgram.js:113:59)
  at findSourceFileWorker (node_modules/typescript/lib/typescript.js:122267:25)
  at findSourceFile (node_modules/typescript/lib/typescript.js:122186:22)
  at node_modules/typescript/lib/typescript.js:122135:24
  at getSourceFileFromReferenceWorker (node_modules/typescript/lib/typescript.js:122104:28)
  at processSourceFile (node_modules/typescript/lib/typescript.js:122133:7)

 ERROR  VirtualCode id must be lowercase: scriptFormat 
navanjr commented 5 days ago

I get the same

Could not map moduleDetection force

When following the quick start steps: https://nuxt.com/docs/guide/going-further/modules#quick-start

btw: downgrading to @nuxt/module-builder:^0.5.0 works

danielroe commented 4 days ago

This is now resolved in mkdist and should be fixed with a lockfile refresh.