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

UnhandledRejection Error: Cannot Find React Package #90

Closed
IvanNavin opened this issue Apr 2, 2024 · 23 comments
Closed

UnhandledRejection Error: Cannot Find React Package #90

IvanNavin opened this issue Apr 2, 2024 · 23 comments
Assignees
Labels
bug Something isn't working

Comments

@IvanNavin
Copy link

I'm encountering an unhandled rejection error with the following details:

64.64 unhandledRejection Error [ERR_MODULE_NOT_FOUND]: Cannot find package '/usr/src/app/node_modules/@phosphor-icons/react/dist/node_modules/.pnpm/react@18.2.0/node_modules/react/' imported from /usr/src/app/node_modules/@phosphor-icons/react/dist/node_modules/.pnpm/react@18.2.0/node_modules/react/cjs/react-jsx-runtime.production.min.mjs
64.64 Did you mean to import react/index.js?
64.64     at new NodeError (node:internal/errors:399:5)
64.64     at legacyMainResolve (node:internal/modules/esm/resolve:235:9)
64.64     at packageResolve (node:internal/modules/esm/resolve:876:14)
64.64     at moduleResolve (node:internal/modules/esm/resolve:938:20)
64.64     at defaultResolve (node:internal/modules/esm/resolve:1153:11)
64.64     at nextResolve (node:internal/modules/esm/loader:163:28)
64.64     at ESMLoader.resolve (node:internal/modules/esm/loader:838:30)
64.64     at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
64.64     at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40)
64.64     at link (node:internal/modules/esm/module_job:76:36) {
64.64   type: 'Error',
64.64   code: 'ERR_MODULE_NOT_FOUND'
64.64 }

It seems like the React package is not being found properly. The error suggests that it cannot locate the React package at a specific path. The message also includes a suggestion: "Did you mean to import react/index.js?"

OS: MacOs, Node.js, Docker
Stack:

  • @phosphor-icons/react version 2.1.4
  • Next.js version 13.4.7
  • React version 18.2.0
  • React-dom version 18.2.0

Global packages:

  • Node.js version 18.16.0
  • npm version 9.8.1

Any insights or guidance on resolving this issue would be greatly appreciated.

@IvanNavin IvanNavin added the bug Something isn't working label Apr 2, 2024
@omridevk
Copy link

omridevk commented Apr 2, 2024

same here

@omridevk
Copy link

omridevk commented Apr 2, 2024

@rektdeckard
Could be related to this ?
2f22ef1
not sure though.
I assume some build issue since it is weird to ship "node_modules" inside of a dist directory.

@oscadev
Copy link

oscadev commented Apr 3, 2024

Same here. Cannot use IconContext.Provider in _app.tsx in a Next JS (pages router) app, or I get the "Did you mean to import "react/index.js"?" crash

@oscadev
Copy link

oscadev commented Apr 3, 2024

@IvanNavin I fixed it. It is because you are importing the ssr version instead of the normal react version. Change your ic import to "import { ArrowArcRight } from "@phosphor-icons/react";" instead of "import { ArrowRight } from "@phosphor-icons/react/dist/ssr";

Update: It was a fluke, or something. The problem is back.

@IvanNavin
Copy link
Author

@oscadev I would be very happy to fix this using that approach, but I don't have a path like '@phosphor-icons/react/dist/ssr' anywhere.
Знімок екрана 2024-04-03 о 07 10 41

@xwu-alterdomus
Copy link

xwu-alterdomus commented Apr 3, 2024

Any update for this issue. it works as expected inprevious version, that is 2.0.15
here are my local env:

  • nextjs : 13.2.4
  • React: 18.2.0
  • react-dom:18.2.0
  • @phosphor-icons/react: 2.1.4
  • nodejs: 18.20.0
  • dockerimage: node:18-alpine

@fanzypantz
Copy link

Can confirm I am seeing the same issue on 2.0.14, building a docker image for production in node:20.10.0

@derFBeste
Copy link

Same here. I updated to Nextjs 14 and React to 18 along with that and that's when the issue started.

  • nextjs: 14.1.4
  • React: 18.2.0
  • react-dom: 18.2.0
  • @phosphor-icons/react: 2.1.4
  • nodejs: 20.12.1
  • package manager: pnpm

Using next dev --turbo to run my dev takes care of the error. Maybe a webpack issue?

@schardev
Copy link

schardev commented Apr 4, 2024

@rektdeckard Could be related to this ? 2f22ef1 not sure though. I assume some build issue since it is weird to ship "node_modules" inside of a dist directory.

Yep. It looks to be this. I fixed it by installing the 2.1.3 package which was released on npm but was never published here on github. It is probably some weird bundling issue but then again why do we even need to ship node_modules with specific react version?

@fanzypantz
Copy link

@rektdeckard Could be related to this ? 2f22ef1 not sure though. I assume some build issue since it is weird to ship "node_modules" inside of a dist directory.

Yep. It looks to be this. I fixed it by installing the 2.1.3 package which was released on npm but was never published here on github. It is probably some weird bundling issue but then again why do we even need to ship node_modules with specific react version?

Are you sure you didn't have this cached? I can't get any of the mentioned versions working nor my old version of 2.0.13 after doing yarn cache clean

My versions:

Node: 20.10.0
"@phosphor-icons/react": "^2.1.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
next": "^12.3.1",

@schardev
Copy link

schardev commented Apr 8, 2024

@fanzypantz yep. I checked it after I did yarn cache clean. Here are my versions:

"dependencies": {
    "@phosphor-icons/react": "2.1.3",
    "next": "14.1.4",
    "react": "18.2.0",
    "react-dom": "18.2.0",
}

@fanzypantz
Copy link

fanzypantz commented Apr 8, 2024

The weird thing, is that this works on my coworkers computer, he also did the cache cleaning, and a random local Linux server we have for development. Edit: He could not build the docker image

But not in our dockerimage, or my local computer. The Dockerfile isn't especially complicated.

# Node version
FROM node:20.10.0 AS builder

ENV NEXT_PUBLIC_API_ENDPOINT=
ENV NEXT_PUBLIC_BASE_URL=

# Install required build tools
RUN apt-get update && \
    apt-get -y install gcc

# Create app directory
WORKDIR /app

# Add the source code to app
COPY package*.json ./
COPY lerna.json ./
COPY /packages ./packages

# Install all the dependencies
RUN yarn install
RUN yarn global add tscpaths

COPY . .

# Generate the build of the application
RUN yarn build

FROM node:20.10.0 AS runner

COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/packages ./packages
COPY --from=builder /app/package*.json ./
COPY --from=builder /app/lerna.json ./

EXPOSE 3000
CMD [ "yarn", "start" ]

@ndom91
Copy link

ndom91 commented Apr 13, 2024

Seeing this issue with the following dependencies as well when we upgraded to 2.1.4.

"dependencies": {
    "@phosphor-icons/react": "^2.1.4",
    "next": "14.2.1",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
}

Importing like so as it reduces the number of modules next.js includes

import { Flask } from "@phosphor-icons/react/dist/csr/Flask"

Downgrading back to @phosphor-icons/react@2.0.15 seems to have fixed it again.

@schardev
Copy link

Importing like so as it reduces the number of modules next.js includes

@ndom91 have you tried optimizePackageImports?

@lcvbeek
Copy link

lcvbeek commented Apr 18, 2024

@rektdeckard Could be related to this ? 2f22ef1 not sure though. I assume some build issue since it is weird to ship "node_modules" inside of a dist directory.

Yep. It looks to be this. I fixed it by installing the 2.1.3 package which was released on npm but was never published here on github. It is probably some weird bundling issue but then again why do we even need to ship node_modules with specific react version?

Are you sure you didn't have this cached? I can't get any of the mentioned versions working nor my old version of 2.0.13 after doing yarn cache clean

My versions:

Node: 20.10.0
"@phosphor-icons/react": "^2.1.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
next": "^12.3.1",

Make sure to use "2.1.3" and not "^2.1.3", as this will still resolve to install "2.1.4" ;)
Check your yarn.lock for what it's actually installing.

@rektdeckard
Copy link
Member

Hi all, apologies for delay in resolving this! Testing the hypothesis that it is caused by relying on automatic JSX runtime, as @omridevk suggests. I will be pushing some pre-release updates to NPM shortly and would appreciate some help testing, as many of these problems are intractable and arise from specific nuances of project setup.

@rektdeckard
Copy link
Member

Have published an alpha that reverts to classic JSX runtime. Checked out locally with next@13.5.1, react@18.2.0, react-dom@18.2.0 on Node 20, but help testing is appreciated!

pnpm install @phosphor-icons/react@next
#                            ^ or @2.1.5-alpha.3

@rektdeckard
Copy link
Member

We had in fact been bundling the automatic JSX runtime, which was expecting to find a version of react in a sibling directory rather than as a global.

This was a non-issue in most builds, since the end-user's build tooling was probably also using automatic JSX runtime, consuming the ESM build of this library, and thus performing the JSX transform itself.

I don't see any harm in reverting to classic JSX runtime. It has marginal performance and bundle impacts, so going ahead and shipping this.

This was referenced Apr 18, 2024
@schardev
Copy link

schardev commented Apr 19, 2024

Can confirm updating to 2.1.5 fixed it for me. Thanks 👍

EDIT:

I don't see any harm in reverting to classic JSX runtime

@rektdeckard was there an issue by externalizing the react/jsx-runtime package? (I can see that you reverted it in ad5be55)

@rektdeckard
Copy link
Member

@schardev it won't work (or at least will error and require an additional package to be installed) for users of react@16 and below. There are still tons of apps running 16.8, and I didn't want to hurt the dev experience there. Impact should really be minimal.

@rektdeckard
Copy link
Member

Seems to have done the trick. I'm marking as resolved.

@IvanNavin
Copy link
Author

Thank you all very much

@omridevk
Copy link

Thanks @rektdeckard !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

10 participants