histoire-dev / histoire

⚡ Fast and beautiful interactive component playgrounds, powered by Vite

Home Page:https://histoire.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error: Cannot find module

vivekrpatel8 opened this issue · comments

Describe the bug

I have a Nuxt project in which I have error.vue file and it uses @datadog/browser-rum library to record the sample sessions. When I run histoire build command it throws following error:
I am not even using error.vue file in histoire but it is automatically calling it in a build.

Error while collecting story /home/exampleFile.story.vue:
Error: Cannot find module /home/user/node_modules/@datadog/browser-rum/esm imported from file:///home/username/repo, file:///home/username/, file:///home/username/repo/_index.js, file:///home/username/node_modules
    at _resolve (file:///home/username/repo/node_modules/mlly/dist/index.mjs:2107:19)
    at resolveSync (file:///home/username/repo/node_modules/mlly/dist/index.mjs:2116:10)
    at resolvePathSync (file:///home/username/repo/node_modules/mlly/dist/index.mjs:2126:24)
    at resolvePath (file:///home/username/repo/node_modules/mlly/dist/index.mjs:2130:28)
    at isValidNodeImport (file:///home/username/repo/node_modules/mlly/dist/index.mjs:2602:30)
    at _shouldExternalize (file:///home/username/repo/node_modules/histoire/node_modules/vite-node/dist/server.mjs:78:32)
    at shouldExternalize (file:///home/username/repo/node_modules/histoire/node_modules/vite-node/dist/server.mjs:55:19)
    at ViteNodeServer.shouldExternalize (file:///home/username/repo/node_modules/histoire/node_modules/vite-node/dist/server.mjs:225:12)
    at ViteNodeServer._fetchModule (file:///home/username/repo/node_modules/histoire/node_modules/vite-node/dist/server.mjs:322:36)
    at ViteNodeServer.fetchModule (file:///home/username/repo/node_modules/histoire/node_modules/vite-node/dist/server.mjs:261:14)
    at Object.fetchModule (file:///home/username/repo/node_modules/histoire/dist/node/collect/index.js:50:37)
    at MessagePort.<anonymous> (file:///home/username/repo/node_modules/birpc/dist/index.mjs:16:41)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:761:20)
    at exports.emitMessage (node:internal/per_context/messageport:23:28)

I have tried to add following in histoire.config.ts but still same issue:

export default defineConfig({
  plugins: [HstVue(), HstNuxt()],
  storyIgnored: ['**/node_modules/**', '**/dist/**', 'error.vue'],
})

Reproduction

Install @datadog/browser-rum library and call it in a error.vue file and run yarn histoire build command

System Info

I am using Nuxt3 and versions are as follows: 
"@histoire/plugin-nuxt": "^0.17.8"
"@histoire/plugin-vue": "^0.17.8"
"histoire": "^0.17.8"
"@datadog/browser-rum": "^5.9.0"

Used Package Manager

yarn

Validations

Having the same issue, but with lucide-vue-next.

For context: using PNPM in an NX monorepo. Have confirmed the folder named after "Cannot find module ..." definitely exists.

In that "esm" folder, it should find "lucide-vue-next.js", as described in "package.json" entrypoints. However, it's failing to do that.

Error while collecting story /Users/user/Code/monorepos.frontend/modules/shared/ui/src/feedback/SelectionSummary.story.vue:
Error: Cannot find module /Users/user/Code/monorepos.frontend/modules/shared/ui/node_modules/.pnpm/lucide-vue-next@0.394.0_vue@3.4.27/node_modules/lucide-vue-next/dist/esm imported from file:///Users/user/Code/monorepos.frontend/modules/shared/ui, file:///Users/user/Code/monorepos.frontend/modules/shared/, file:///Users/user/Code/monorepos.frontend/modules/shared/ui/_index.js, file:///Users/user/Code/monorepos.frontend/modules/shared/node_modules
    at _resolve (file:///Users/user/Code/monorepos.frontend/node_modules/.pnpm/mlly@1.7.1/node_modules/mlly/dist/index.mjs:2102:19)
    at resolveSync (file:///Users/user/Code/monorepos.frontend/node_modules/.pnpm/mlly@1.7.1/node_modules/mlly/dist/index.mjs:2111:10)
    at resolvePathSync (file:///Users/user/Code/monorepos.frontend/node_modules/.pnpm/mlly@1.7.1/node_modules/mlly/dist/index.mjs:2121:24)
    at resolvePath (file:///Users/user/Code/monorepos.frontend/node_modules/.pnpm/mlly@1.7.1/node_modules/mlly/dist/index.mjs:2125:28)
    at isValidNodeImport (file:///Users/user/Code/monorepos.frontend/node_modules/.pnpm/mlly@1.7.1/node_modules/mlly/dist/index.mjs:2585:30)
    at _shouldExternalize (file:///Users/user/Code/monorepos.frontend/node_modules/.pnpm/vite-node@0.34.7_@types+node@18.16.9_sass@1.62.1/node_modules/vite-node/dist/server.mjs:78:32)
    at shouldExternalize (file:///Users/user/Code/monorepos.frontend/node_modules/.pnpm/vite-node@0.34.7_@types+node@18.16.9_sass@1.62.1/node_modules/vite-node/dist/server.mjs:55:19)
    at ViteNodeServer.shouldExternalize (file:///Users/user/Code/monorepos.frontend/node_modules/.pnpm/vite-node@0.34.7_@types+node@18.16.9_sass@1.62.1/node_modules/vite-node/dist/server.mjs:225:12)
    at ViteNodeServer._fetchModule (file:///Users/user/Code/monorepos.frontend/node_modules/.pnpm/vite-node@0.34.7_@types+node@18.16.9_sass@1.62.1/node_modules/vite-node/dist/server.mjs:322:36)
    at ViteNodeServer.fetchModule (file:///Users/user/Code/monorepos.frontend/node_modules/.pnpm/vite-node@0.34.7_@types+node@18.16.9_sass@1.62.1/node_modules/vite-node/dist/server.mjs:261:14)```

@harrynikolov-riskhub I was able to resolve mine by using following solution: #712