N
Nuxtβ€’2y ago
dmarr

Linked ESM package not found

I am trying to import from a linked package that I've built with vite (in library mode). When I try to run the dev script, I get:
Failed to load url /@fs/Users/david.marr/code/ui-components/packages/Utils/lib/index.mjs (resolved id: /Users/david.marr/code/ui-components/packages/Utils/lib/index.mjs) in /Users/david.marr/code/app/src/plugins/filters.js. Does the file exist?
I don't have type: 'module' in either the app or the package i'm trying to import. I've linked the package and verified that it is in node_modules. Not sure what the issue is... If I run the build script, the issue doesn't appear. I also am able to import this package in a fresh nuxt 3 app, so maybe there is something with linking that is the issue?
18 Replies
dmarr
dmarrβ€’2y ago
seems like i'm required to use .ts extension and lang="ts" in my vue files well removing my old jsconfig.json seems to get past that, but now I get the same error on a vue file
Unknown User
Unknown Userβ€’2y ago
Message Not Public
Sign In & Join Server To View
dmarr
dmarrβ€’2y ago
so in package's package.json:
"main": "index.js",
"module": "lib/index.mjs",
"type": "module",
"main": "index.js",
"module": "lib/index.mjs",
"type": "module",
in the lib/ dir, the index.mjs file is present would having a jsconfig.json file impact anything? I'm trying to narrow down why a clean nuxt3 project can import just fine, but my nuxt2->nuxt3 upgrade cannot appears I need to add to vite config in nuxt.config.js:
vite: {
optimizeDeps: {
include: ['my-linked-package']
},
}
vite: {
optimizeDeps: {
include: ['my-linked-package']
},
}
Unknown User
Unknown Userβ€’2y ago
Message Not Public
Sign In & Join Server To View
dmarr
dmarrβ€’2y ago
yeah i tried both. i think something about the package being linked was causing issues
Unknown User
Unknown Userβ€’17mo ago
Message Not Public
Sign In & Join Server To View
dmarr
dmarrβ€’17mo ago
Hi, I havent found a solution. I ended up starting a new monorepo and I'm moving things over 😦
Unknown User
Unknown Userβ€’17mo ago
Message Not Public
Sign In & Join Server To View
dmarr
dmarrβ€’17mo ago
ok thanks. I was playing around with the vite section of nuxt config.
vite: {
optimizeDeps: {
include: [
'my-linked-repo',
]
}
}
vite: {
optimizeDeps: {
include: [
'my-linked-repo',
]
}
}
i don't know why but it seemed to get past some errors, but something with the way my external package (using vite lib mode) was built that nuxt didn't like the other crappy workaround was npm pack in the external package and installing from that
Unknown User
Unknown Userβ€’17mo ago
Message Not Public
Sign In & Join Server To View
πŸ‡¨πŸ‡­ Marko Bolliger <cannap>
maybe transpile it
Unknown User
Unknown Userβ€’17mo ago
Message Not Public
Sign In & Join Server To View
dmarr
dmarrβ€’17mo ago
Thank you @Nobsow -- good work! I will give it a try today
Unknown User
Unknown Userβ€’17mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server