Open mataspetrikas opened 2 months ago
Hey, I faced a similar issue here when trying to compile the project with react-cookie@7.2.0. I got the following error:
Failed to compile.
Error in ./~/react-cookie/cjs/index.js
Module not found: 'universal-cookie' in /node_modules/react-cookie/cjs
@ ./~/react-cookie/cjs/index.js 3:14-41
Upon checking the index.js file, it pointed to the error related to universal-cookie not being resolved correctly. Hereโs the part of the code causing the issue:
var Cookies = require('universal-cookie');
var React = require('react');
var hoistStatics = require('hoist-non-react-statics');
Here's my package.json dependencies for reference:
"dependencies": {
"dotenv": "^16.4.5",
"react": "^18.3.1",
"react-cookie": "^7.2.0",
"react-dom": "^18.3.1",
"react-scripts": "0.9.5",
"universal-cookie": "^7.2.0"
}
I tried using ES module imports instead of require(), but ultimately, the issue was resolved when I downgraded to an older version of react-cookie. Specifically, I used react-cookie@6.1.1 while keeping universal-cookie@7.2.0.
I suspect this issue is related to #705 You could try the temporary fix in the first post and check if the module resolution issue goes away.
Can you try with v7.2.2 and let me know if you have the same issue?
@eXon v7.2.2 has resolved the issue for me.
Edit: Actually, scratch that, with 7.2.2 I'm still getting issues with ESLint import/no-unresolved (https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-unresolved.md)
...\cookies.ts
1:21 error Unable to resolve path to module 'universal-cookie' import/no-unresolved
โ 1 problem (1 error, 0 warnings)
The file looks like:
import Cookies from "universal-cookie";
export const cookies = new Cookies();
And using a relative path resolves it:
import Cookies from "../../node_modules/universal-cookie";
export const cookies = new Cookies();
We have the same issue with react-cookie
>= v7.2.0
. The eslint plugin import-x cannot resolve the import.
v7.1.4` resolves correctly
Our setup (base):
I have tried updating the import from
universal-cookie@7.1.4
touniversal-cookie@7.2.0
, when runningpnpm build
, I get the following error:When I downgrade back to
universal-cookie@7.1.4
and delete the.next
folder, the build works again. Do you maybe have an idea what needs to be done in that case? Thank you ๐