Cannot find module './stringify'
Version
"@nuxtjs/strapi": "^1.12.0", "nuxt": "^3.11.2", "vue": "^3.4.27", "vue-router": "^4.3.2"
Steps to reproduce
I have a clean Nuxt installation. Add the package how it's recommended and after the dev server breaks with the following error:
[nuxt] [request error] [unhandled] [500] Cannot find module './stringify'
Require stack:
- /Users/administrator/Documents/Projekte/testNuxt/qs
at Function._resolveFilename (node:internal/modules/cjs/loader:1143:15)
at Function._load (node:internal/modules/cjs/loader:984:27)
at Module.require (node:internal/modules/cjs/loader:1231:19)
at require (node:internal/modules/helpers:179:18)
at ./qs:3:17
at ViteNodeRunner.runModule (./node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:362:11)
at ViteNodeRunner.directRequest (./node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:346:16)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async ViteNodeRunner.cachedRequest (./node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:189:14)
at async ViteNodeRunner.dependencyRequest (./node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:233:12)
I investigated that this only happen when u install the package with pnpm
I have the same issue. Using pnpm too. Any solution?
I haven't looked at the "why", but adding qs@5 to the nuxt project seems to work (pnpm add qs@^5.2.1).
Same issue, using pnpm too
PNPM structures it's dependencies differently and doesn't allow dependencies to access each other (shamefully-hosting). This is an issue with how the 'qs' dependency is accessed.
Simple fixes are adding the qs dependency yourself or enabling shamefully-hosting, but end goal should be that this is fixed in the package itself. My understanding is too limited to propose a fix but have a look at these issues for more information.
https://github.com/nuxt/nuxt/issues/14146 https://github.com/nuxt-modules/i18n/issues/2506
Issue
Before a week ago, I've lunched a blog feature on a live website with this module and Strapi v5. Wanted to test even more some of the new Strapi features, so yesterday I've made new installation and module is not working anymore. Must say that it was a big surprise as everything was working just fine a week ago. I've tried to downgrade Nuxt, Vite, install qs, etc. but nothing seems to work.
So again I made a fresh installation just to be sure, again with npm:
"dependencies": { "@nuxtjs/strapi": "^2.0.0", "nuxt": "^3.14.1592", "vue": "latest", "vue-router": "latest" }
export default defineNuxtConfig({ compatibilityDate: "2024-11-01", devtools: { enabled: true }, modules: ['@nuxtjs/strapi'] });
Result:
when
'@nuxtjs/strapi'is not included everything works fine
Any thoughts on what to do or what to expect from this module are highly appreciated. Thanks
This may have something to do with how a specific dependency(qs) is imported and use.
Had a similar issue with a package of mine and the pnpm users. I think if we updated how the import is done along with adding qs as a dependency instead of a devDeps, it will solve the issue. I will take a look at it
@BayBreezy ...thank you very much.
Solution found for my problem: https://github.com/nuxt/nuxt/issues/30749#issuecomment-2613999221 Seems to be a problem with Nuxt 3.15.3
Previous comment
I'm experiencing the same problem using yarn and workspaces.
npx nuxi info outrput:
- Operating System: Linux
- Node Version: v20.18.1
- Nuxt Version: 3.15.3
- CLI Version: 3.20.0
- Nitro Version: 2.10.4
- Package Manager: [email protected]
- Builder: -
- User Config: -
- Runtime Modules: -
- Build Modules: -
The error:
[nuxt] [request error] [unhandled] [500] Cannot find module './stringify'
Require stack:
- /home/luke/projects/kmuip/conmgmt/packages/app/qs
I tried several approaches, from using nohoist in the package.json workspace definition to pinning a specific version using resolutions.
I tried it with @nuxtjs/strapi version 1.12.0 and 2.0.0
The moment I remove @nuxtjs/strapi from the modules in nuxt.config.ts, it works.
I made sure to clean up everything in between installs (remove node_modules, clear the yarn cache, remove yarn.lock)
Edit: Removing the import of stringify also resolves the problem: https://github.com/nuxt-modules/strapi/blob/a18813585054a086bea019ea164569024ed1fa02/src/runtime/composables/useStrapiClient.ts#L2
Edit 2, workaround: Changing the imports of stringify, parse and formats from require to "import from" seems to resolve the issue for me. I had to change the index.js file (node_modules/qs/lib/index.js) in the workspace node_modules folder.
'use strict';
var stringify = require('./stringify');
var parse = require('./parse');
var formats = require('./formats');
module.exports = {
formats: formats,
parse: parse,
stringify: stringify
};
to
'use strict';
import stringify from './stringify.js';
import parse from './parse.js';
import formats from './formats.js';
module.exports = {
formats: formats,
parse: parse,
stringify: stringify
};
I don't know why exactly
Thanks luke-z
I haven't looked at the "why", but adding
qs@5to the nuxt project seems to work (pnpm add qs@^5.2.1).
Same for me.