bendotcodes / cookies

Load and save cookies within your Web application
MIT License
157 stars 18 forks source link

Unable to resolve path to module 'universal-cookie' after update to 7.2.0 #624

Open mataspetrikas opened 2 months ago

mataspetrikas commented 2 months ago

Our setup (base):

"next": "^14.2.5",
"typescript": "^5.5.4"
"eslint-import-resolver-typescript": "^3.6.1",
"eslint": "^8.57.0",
 "turbo": "^2.0.12"
...

I have tried updating the import from universal-cookie@7.1.4 to universal-cookie@7.2.0, when running pnpm build, I get the following error:

web:build: ./src/components/navigation/language-switcher.tsx
web:build: 5:21  Error: Unable to resolve path to module 'universal-cookie'.  import/no-unresolved

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 ๐Ÿ™

AditUB commented 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.

neilflatley commented 3 weeks ago

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.

eXon commented 1 week ago

Can you try with v7.2.2 and let me know if you have the same issue?

neoGeneva commented 1 week ago

@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();
MarcRoemmelt commented 6 days ago

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