Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mataspetrikas opened this issue Aug 14, 2024 · 5 comments

Comments

@mataspetrikas
Copy link

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 [email protected] to [email protected], 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 [email protected] 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
Copy link

AditUB commented Aug 28, 2024

Hey, I faced a similar issue here when trying to compile the project with [email protected].
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 [email protected] while keeping [email protected].

@neilflatley
Copy link

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
Copy link
Collaborator

eXon commented Oct 29, 2024

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

@neoGeneva
Copy link

neoGeneva commented Oct 29, 2024

@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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants