N
Nuxt2mo ago
Anno

TypeError: Failed to resolve module specifier ".prisma/client/index-browser"

Hey guys, so im working on my first nuxt.js project and I have been reading and searching for a couple of hours now. I have a dedicated vps to run this app with the db on it too. When I start the application using: npm run dev everything works perfectly. --> I can load the webpage without any errors in the console or log or anything and all data is present. When I start the application using: npm run build and node ./outputserver/index.mjs my page is not being loaded properly anymore. and I get this error: Uncaught TypeError: Failed to resolve module specifier ".prisma/client/index-browser". Relative references must start with either "/", "./", or "../". but trying the api directly I can access the data. so /api/guildStats for example works out perfectly fine. so I know the connection to the database is not the problem. this is how I try to get the data: onMounted(async () => { try { const response = await fetch('/api/guildStats'); guild.value = await response.json(); } catch (error) { console.error("Error fetching guild data:", error); } }); if I forgot anything or you need to know more specifics please let me know. Thanks for helping me out!
4 Replies
kapa.ai
kapa.ai2mo ago
Hi @Anno. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information provided in your question, it seems you're encountering an issue with module resolution when running your Nuxt.js application in production mode. This error is likely related to how Prisma Client is being imported and used in your project. Let's address this issue step by step: 1. The error you're seeing (Failed to resolve module specifier ".prisma/client/index-browser") suggests that there's a problem with how Prisma Client is being imported or bundled in your production build. 2. The fact that your application works correctly in development mode (npm run dev) but not in production (npm run build and node ./outputserver/index.mjs) indicates that there might be a difference in how modules are resolved between these environments. To resolve this issue, you can try the following steps: 1. Transpile Prisma Client: Add Prisma Client to the build.transpile array in your nuxt.config.ts file. This will ensure that Prisma Client is properly transpiled during the build process:
export default defineNuxtConfig({
build: {
transpile: ['@prisma/client']
}
})

export default defineNuxtConfig({
build: {
transpile: ['@prisma/client']
}
})

Source: Troubleshooting ESM Issues (https://nuxt.com/docs/guide/concepts/esm#troubleshooting-esm-issues) 2. If the above step doesn't resolve the issue, you might need to manually alias the Prisma Client library. Add this to your nuxt.config.ts:
export default defineNuxtConfig({
alias: {
'.prisma/client/index-browser': '@prisma/client'
}
})

export default defineNuxtConfig({
alias: {
'.prisma/client/index-browser': '@prisma/client'
}
})

Source: Troubleshooting ESM Issues (https://nuxt.com/docs/guide/concepts/esm#troubleshooting-esm-issues) 3. Ensure that your Prisma Client is properly generated and up-to-date. Run npx prisma generate before building your application. 4. Double-check that you're using the latest version of Prisma Client and Nuxt.js, as newer versions might have resolved this issue. 5. If you're using TypeScript, make sure your tsconfig.json is properly configured to handle module resolution. Regarding your data fetching code, it looks correct. The issue doesn't seem to be related to how you're fetching data, but rather how the Prisma Client module is being resolved in the production build. If these steps don't resolve your issue, you might need to investigate further. Consider checking your Nuxt.js and Prisma configurations, and ensure that all dependencies are correctly installed and compatible with each other. Remember to rebuild your application after making these changes:
npm run build
node ./output/server/index.mjs
npm run build
node ./output/server/index.mjs
If the problem persists, you may need to report a bug (https://nuxt.com/docs/community/reporting-bugs#figure-out-what-the-cause-might-be) to the Nuxt.js or Prisma teams, as it could be related to how these libraries interact in a production environment. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@139000387016327168> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Anno
AnnoOP2mo ago
those were the exact ideas that I got back from chatgpt and I tried them a couple of hours ago already. sadly they didt work for me and the issue persists.
Anno
AnnoOP2mo ago
incase anyone ever has the same issue, thanks to @Patrik https://www.answeroverflow.com/m/1246797520471064617
Getting Prisma TypeError in the browser console in a SolidStart app...
The error: TypeError: Failed to resolve module specifier ".prisma/client/index-browser". Relative references must start with either "/", "./", or "../". I will work on reproducing this. Development build works.
Want results from more Discord servers?
Add your server