remix
remix copied to clipboard
Cannot find module error on fresh build
What version of Remix are you using?
@latest 1.11.1
Steps to Reproduce
npx create-remix@latest remix-test Just the basics Vercel Typscript Install? Yes cd remix-test npm run dev
Node versions tried: 18.12.1, 18.13.0, 19.4.0. Browsers tried. Chrome, Safari. I got the same error with the Indie stack following the tutorial directions.
Expected Behavior
Default greeting page after running npm run dev
Actual Behavior
Error: Cannot find module '/Users/thaddeuskrugman/Desktop/remix-test/api/index.js' Require stack:
- /Users/thaddeuskrugman/Desktop/remix-test/node_modules/@remix-run/serve/dist/index.js
- /Users/thaddeuskrugman/Desktop/remix-test/node_modules/@remix-run/dev/dist/devServer/serve.js
- /Users/thaddeuskrugman/Desktop/remix-test/node_modules/@remix-run/dev/dist/cli/commands.js
- /Users/thaddeuskrugman/Desktop/remix-test/node_modules/@remix-run/dev/dist/cli/run.js
- /Users/thaddeuskrugman/Desktop/remix-test/node_modules/@remix-run/dev/dist/cli/index.js
- /Users/thaddeuskrugman/Desktop/remix-test/node_modules/@remix-run/dev/dist/index.js
- /Users/thaddeuskrugman/Desktop/remix-test/node_modules/@remix-run/dev/dist/cli.js at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1053:15) at Function.Module._load (node:internal/modules/cjs/loader:898:27) at Module.require (node:internal/modules/cjs/loader:1120:19) at require (node:internal/modules/helpers:112:18) at /Users/thaddeuskrugman/Desktop/remix-test/node_modules/@remix-run/serve/dist/index.js:43:17 at Layer.handle [as handle_request] (/Users/thaddeuskrugman/Desktop/remix-test/node_modules/express/lib/router/layer.js:95:5) at next (/Users/thaddeuskrugman/Desktop/remix-test/node_modules/express/lib/router/route.js:144:13) at next (/Users/thaddeuskrugman/Desktop/remix-test/node_modules/express/lib/router/route.js:140:7) at next (/Users/thaddeuskrugman/Desktop/remix-test/node_modules/express/lib/router/route.js:140:7) at next (/Users/thaddeuskrugman/Desktop/remix-test/node_modules/express/lib/router/route.js:140:7)
I just tried your reproduction and it works perfectly for me.
Could you provide us with a public repository that fails for you?
Here is a link to the public repository I just created. https://github.com/MadThad762/remix-test
Works fine here as well:
🍺 ~ $ git clone [email protected]:MadThad762/remix-test.git
Cloning into 'remix-test'...
remote: Enumerating objects: 19, done.
remote: Counting objects: 100% (19/19), done.
remote: Compressing objects: 100% (17/17), done.
remote: Total 19 (delta 0), reused 19 (delta 0), pack-reused 0
Receiving objects: 100% (19/19), 132.97 KiB | 627.00 KiB/s, done.
🍺 ~ $ cd remix-test/
🍺 ~/remix-test (main)$ node -v
v18.11.0
🍺 ~/remix-test (main)$ npm i
npm WARN deprecated [email protected]: See https://github.com/lydell/source-map-resolve#deprecated
npm WARN deprecated [email protected]: Please use @jridgewell/sourcemap-codec instead
npm WARN deprecated [email protected]: See https://github.com/lydell/source-map-url#deprecated
npm WARN deprecated [email protected]: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-inject.
npm WARN deprecated @npmcli/[email protected]: This functionality has been moved to @npmcli/fs
npm WARN deprecated [email protected]: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated [email protected]: Please see https://github.com/lydell/urix#deprecated
added 1136 packages, and audited 1137 packages in 1m
238 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
🍺 ~/remix-test (main)$ npm run dev
> dev
> remix dev
Remix App Server started at http://localhost:3000 (http://192.168.1.9:3000)
GET / 200 - - 34.167 ms
Could you use the same commands as I did and copy/paste your session?
Last login: Sun Jan 22 04:17:16 on ttys000 thaddeuskrugman@Thaddeuss-MacBook-Pro ~ % cd desktop thaddeuskrugman@Thaddeuss-MacBook-Pro desktop % git clone [email protected]:MadThad762/remix-test.git Cloning into 'remix-test'... [email protected]: Permission denied (publickey). fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists. thaddeuskrugman@Thaddeuss-MacBook-Pro desktop % git clone [email protected]:MadThad762/remix-test.git Cloning into 'remix-test'... [email protected]: Permission denied (publickey). fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists. thaddeuskrugman@Thaddeuss-MacBook-Pro desktop % clear
thaddeuskrugman@Thaddeuss-MacBook-Pro desktop % git clone https://github.com/MadThad762/remix-test.git Cloning into 'remix-test'... remote: Enumerating objects: 19, done. remote: Counting objects: 100% (19/19), done. remote: Compressing objects: 100% (17/17), done. remote: Total 19 (delta 0), reused 19 (delta 0), pack-reused 0 Receiving objects: 100% (19/19), 132.97 KiB | 382.00 KiB/s, done. thaddeuskrugman@Thaddeuss-MacBook-Pro desktop % cd remix-test thaddeuskrugman@Thaddeuss-MacBook-Pro remix-test % node --v node: bad option: --v thaddeuskrugman@Thaddeuss-MacBook-Pro remix-test % node -v v19.4.0 thaddeuskrugman@Thaddeuss-MacBook-Pro remix-test % npm i npm WARN deprecated @npmcli/[email protected]: This functionality has been moved to @npmcli/fs npm WARN deprecated [email protected]: See https://github.com/lydell/source-map-url#deprecated npm WARN deprecated [email protected]: Please see https://github.com/lydell/urix#deprecated npm WARN deprecated [email protected]: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-inject. npm WARN deprecated [email protected]: https://github.com/lydell/resolve-url#deprecated npm WARN deprecated [email protected]: See https://github.com/lydell/source-map-resolve#deprecated npm WARN deprecated [email protected]: Please use @jridgewell/sourcemap-codec instead
added 1136 packages, and audited 1137 packages in 11s
238 packages are looking for funding
run npm fund
for details
found 0 vulnerabilities thaddeuskrugman@Thaddeuss-MacBook-Pro remix-test % npm run dev
dev remix dev
Remix App Server started at http://localhost:3000 (http://192.168.4.22:3000) Error: Cannot find module '/Users/thaddeuskrugman/Desktop/remix-test/api/index.js' Require stack:
- /Users/thaddeuskrugman/Desktop/remix-test/node_modules/@remix-run/serve/dist/index.js
- /Users/thaddeuskrugman/Desktop/remix-test/node_modules/@remix-run/dev/dist/devServer/serve.js
- /Users/thaddeuskrugman/Desktop/remix-test/node_modules/@remix-run/dev/dist/cli/commands.js
- /Users/thaddeuskrugman/Desktop/remix-test/node_modules/@remix-run/dev/dist/cli/run.js
- /Users/thaddeuskrugman/Desktop/remix-test/node_modules/@remix-run/dev/dist/cli/index.js
- /Users/thaddeuskrugman/Desktop/remix-test/node_modules/@remix-run/dev/dist/index.js
- /Users/thaddeuskrugman/Desktop/remix-test/node_modules/@remix-run/dev/dist/cli.js at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1053:15) at Function.Module._load (node:internal/modules/cjs/loader:898:27) at Module.require (node:internal/modules/cjs/loader:1120:19) at require (node:internal/modules/helpers:112:18) at /Users/thaddeuskrugman/Desktop/remix-test/node_modules/@remix-run/serve/dist/index.js:43:17 at Layer.handle [as handle_request] (/Users/thaddeuskrugman/Desktop/remix-test/node_modules/express/lib/router/layer.js:95:5) at next (/Users/thaddeuskrugman/Desktop/remix-test/node_modules/express/lib/router/route.js:144:13) at next (/Users/thaddeuskrugman/Desktop/remix-test/node_modules/express/lib/router/route.js:140:7) at next (/Users/thaddeuskrugman/Desktop/remix-test/node_modules/express/lib/router/route.js:140:7) at next (/Users/thaddeuskrugman/Desktop/remix-test/node_modules/express/lib/router/route.js:140:7) GET / 500 - - 5.182 ms
could you try running:
NODE_ENV=development npm run dev
and tell me what it yields?
I just tried it and it yields the same results. GET / 500
I just deployed it to vercel and it builds and deploys successfully. What is it about my machine that is causing the error?
Edit: Vite, Next, CRA, etc all run without issues.
npm run dev
should be creating a api/index.js
file in your root directory, this doesn't seem to be the case.
Can you maybe uncomment serverBuildPath: "api/index.js",
in remix.config.js and try again? 🤷🏼♂️
I tried that and I didn't see any difference.
Here is what happens if I run npm run build on my local machine...
thaddeuskrugman@Thaddeuss-MacBook-Pro remix-test % npm run build
build remix build
Building Remix app in production mode...
✘ [ERROR] Could not resolve "@remix-run/react"
app/entry.client.tsx:1:29:
1 │ import { RemixBrowser } from "@remix-run/react";
╵ ~~~~~~~~~~~~~~~~~~
The Yarn Plug'n'Play manifest forbids importing "@remix-run/react" here because it's not listed as a dependency of this package:
../../.pnp.cjs:68:33:
68 │ "packageDependencies": [
╵ ^
You can mark the path "@remix-run/react" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "react"
app/entry.client.tsx:2:44:
2 │ import { startTransition, StrictMode } from "react";
╵ ~~~~~~~
The Yarn Plug'n'Play manifest forbids importing "react" here because it's not listed as a dependency of this package:
../../.pnp.cjs:68:33:
68 │ "packageDependencies": [
╵ ^
You can mark the path "react" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "react-dom/client"
app/entry.client.tsx:3:28:
3 │ import { hydrateRoot } from "react-dom/client";
╵ ~~~~~~~~~~~~~~~~~~
The Yarn Plug'n'Play manifest forbids importing "react-dom" here because it's not listed as a dependency of this package:
../../.pnp.cjs:68:33:
68 │ "packageDependencies": [
╵ ^
You can mark the path "react-dom/client" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "react/jsx-runtime"
app/entry.client.tsx:10:8:
10 │ <RemixBrowser />
╵ ^
The Yarn Plug'n'Play manifest forbids importing "react" here because it's not listed as a dependency of this package:
../../.pnp.cjs:68:33:
68 │ "packageDependencies": [
╵ ^
You can mark the path "react/jsx-runtime" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@remix-run/react"
app/root.tsx:9:7:
9 │ } from "@remix-run/react";
╵ ~~~~~~~~~~~~~~~~~~
The Yarn Plug'n'Play manifest forbids importing "@remix-run/react" here because it's not listed as a dependency of this package:
../../.pnp.cjs:68:33:
68 │ "packageDependencies": [
╵ ^
You can mark the path "@remix-run/react" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "react/jsx-runtime"
app/root.tsx:20:6:
20 │ <head>
╵ ^
The Yarn Plug'n'Play manifest forbids importing "react" here because it's not listed as a dependency of this package:
../../.pnp.cjs:68:33:
68 │ "packageDependencies": [
╵ ^
You can mark the path "react/jsx-runtime" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "react/jsx-runtime"
app/routes/index.tsx:4:6:
4 │ <h1>Welcome to Remix</h1>
╵ ^
The Yarn Plug'n'Play manifest forbids importing "react" here because it's not listed as a dependency of this package:
../../.pnp.cjs:68:33:
68 │ "packageDependencies": [
╵ ^
You can mark the path "react/jsx-runtime" as external to exclude it from the bundle, which will remove this error.
Build failed with 7 errors: app/entry.client.tsx:1:29: ERROR: Could not resolve "@remix-run/react" app/entry.client.tsx:2:44: ERROR: Could not resolve "react" app/entry.client.tsx:3:28: ERROR: Could not resolve "react-dom/client" app/entry.client.tsx:10:8: ERROR: Could not resolve "react/jsx-runtime" app/root.tsx:9:7: ERROR: Could not resolve "@remix-run/react" ... Error at Object.onCompileFailure (/Users/thaddeuskrugman/Desktop/remix-test/node_modules/@remix-run/dev/dist/cli/commands.js:179:13) at Object.compile (/Users/thaddeuskrugman/Desktop/remix-test/node_modules/@remix-run/dev/dist/compiler/remixCompiler.js:33:134) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async Object.build (/Users/thaddeuskrugman/Desktop/remix-test/node_modules/@remix-run/dev/dist/compiler/build.js:33:3) at async Object.build (/Users/thaddeuskrugman/Desktop/remix-test/node_modules/@remix-run/dev/dist/cli/commands.js:174:3) at async Object.run (/Users/thaddeuskrugman/Desktop/remix-test/node_modules/@remix-run/dev/dist/cli/run.js:448:7)
I got the same error with last version (1.12.0):
Steps:
- Fresh update, remove
.cache
,api/
,node_modules
,package-lock.json
-
npm i
(with remix 1.12.0) -
npm run dev
=>/500
withError: Cannot find module '<PROJECT_PATH>/api/index.js'
I got the same error with last version (1.12.0):
Steps:
Fresh update, remove
.cache
,api/
,node_modules
,package-lock.json
npm i
(with remix 1.12.0)
npm run dev
=>/500
withError: Cannot find module '<PROJECT_PATH>/api/index.js'
Were you able to get it working?
I have the same error but with fresh basic layout for cloudflare workers. Node 16.15.3, fresh build.
Build failed with 7 errors:
app/entry.client.tsx:1:29: ERROR: Could not resolve "@remix-run/react"
app/entry.client.tsx:2:44: ERROR: Could not resolve "react"
app/entry.client.tsx:3:28: ERROR: Could not resolve "react-dom/client"
app/entry.client.tsx:10:8: ERROR: Could not resolve "react/jsx-runtime"
app/root.tsx:9:7: ERROR: Could not resolve "@remix-run/react"
...
Error
at Object.onCompileFailure (/Users/dex157/ws/conft/test/node_modules/@remix-run/dev/dist/cli/commands.js:180:13)
at Object.compile (/Users/dex157/ws/conft/test/node_modules/@remix-run/dev/dist/compiler/remixCompiler.js:34:134)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Object.build (/Users/dex157/ws/conft/test/node_modules/@remix-run/dev/dist/compiler/build.js:33:3)
at async Object.build (/Users/dex157/ws/conft/test/node_modules/@remix-run/dev/dist/cli/commands.js:175:3)
at async Object.run (/Users/dex157/ws/conft/test/node_modules/@remix-run/dev/dist/cli/run.js:449:7)
error Command failed with exit code 1.
I've found .pnp.cjs
file in a folder with my projects and removed it. It helps. .pnp.cjs
also can be located in the home folder
I ran into this error. Running remix build
then rerunning remix dev
fixed the issue. I wonder if perhaps remix dev
is not generating the build directory on its own if it doesn't exist.
I've found
.pnp.cjs
file in a folder with my projects and removed it. It helps..pnp.cjs
also can be located in the home folder
This one seems to work. Running separately remix build
didn't solve the issue.
There may be some error in your code, building the app will show you exactly the error that is causing this issue.
In my case:
✘ [ERROR] Could not resolve "../../../styles/images/sign-up-section-image.jpg"
app/components/sections/signup-section.tsx:2:24:
2 │ ...SignupImage from "../../../styles/images/sign-up-section-image.jpg"
sign-up-section-image.jpg was not on that path yet.
Hey I ran up against the The Yarn Plug'n'Play manifest forbids importing "react" here because it's not listed as a dependency of this package:
... You can mark the path "react/jsx-runtime" as external to exclude it from the bundle, which will remove this error. ✘ [ERROR] Could not resolve "react/jsx-runtime"
error message
I am using yarn monorepo. and was wondering how to fix?
I can reproduce this issue when future.v2_routeConvention
is enabled in remix.config.js
in a fresh project before running dev
. Repro here.
I'm having the same issue, haven't been able to solve it.
I've found
.pnp.cjs
file in a folder with my projects and removed it. It helps..pnp.cjs
also can be located in the home folder
this works for me. can somebody explains why is this happening
I don't have a .pnp.cjs file in any of my folders.
I just deleted my build directory and hit this, not sure if it helps or not. Debugging it now.
Edit - it was because I had broken code in one of my components, I guess that initial build couldn't run. If I go around to files and hit save, it gave me the output error. Upon fixing, it ran fine
After upgrading Remix to v1.14.0 and deleting entry.server.ts
and entry.client.ts
, builds fine locally, but I'm getting this error on Vercel:
✘ [ERROR] Could not resolve "@remix-run/react"
--
22:21:34.423 |
22:21:34.423 | ../../var/task/node_modules/@remix-run/dev/dist/config/defaults/entry.client.react.tsx:1:29:
22:21:34.423 | 1 │ import { RemixBrowser } from "@remix-run/react";
22:21:34.423 | ╵ ~~~~~~~~~~~~~~~~~~
22:21:34.423 |
22:21:34.424 | You can mark the path "@remix-run/react" as external to exclude it from the bundle, which will remove this error.
Edit: Adding the files back solved the issue 🎉
Here are the files if you need them.
I created first time remix-app and I dont see same files in my project. It doesnt create entry.client.tsx and entry.server.tsx. How can I create same project?
@andrecasal called it. I've been fighting with this for days because it's my first time deploying a Vercel app using Remix and Nx 😩 Turns out it wasn't due to Nx or pnpm... it was just those missing files. The docs say you can use npx remix reveal
to bring them back. For some reason, npx
says it cannot find the proper executable for remix
. So I did this and it's working now 🎉
./node_modules/.bin/remix reveal
@brian-dlee I was going through the docs and couldn't find a reference to npx remix reveal
, could you please point me to it?
@brian-dlee I was going through the docs and couldn't find a reference to
npx remix reveal
, could you please point me to it?
@andrecasal Ah, it wasn't in the docs! I found it in the 1.14.0 release notes.
https://github.com/remix-run/remix/releases/tag/remix%401.14.0
It's listed in the first bullet in "Other notable changes".
@brian-dlee Got it, thanks!
I installed a fresh app in Intellj with the plugin and was running into this error. I ran npm rebuild
and was able to get it going.
I tried that and I didn't see any difference.
Here is what happens if I run npm run build on my local machine...
thaddeuskrugman@Thaddeuss-MacBook-Pro remix-test % npm run build
build remix build
Building Remix app in production mode...
✘ [ERROR] Could not resolve "@remix-run/react"
app/entry.client.tsx:1:29: 1 │ import { RemixBrowser } from "@remix-run/react"; ╵ ~~~~~~~~~~~~~~~~~~
The Yarn Plug'n'Play manifest forbids importing "@remix-run/react" here because it's not listed as a dependency of this package:
../../.pnp.cjs:68:33: 68 │ "packageDependencies": [ ╵ ^
You can mark the path "@remix-run/react" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "react"
app/entry.client.tsx:2:44: 2 │ import { startTransition, StrictMode } from "react"; ╵ ~~~~~~~
The Yarn Plug'n'Play manifest forbids importing "react" here because it's not listed as a dependency of this package:
../../.pnp.cjs:68:33: 68 │ "packageDependencies": [ ╵ ^
You can mark the path "react" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "react-dom/client"
app/entry.client.tsx:3:28: 3 │ import { hydrateRoot } from "react-dom/client"; ╵ ~~~~~~~~~~~~~~~~~~
The Yarn Plug'n'Play manifest forbids importing "react-dom" here because it's not listed as a dependency of this package:
../../.pnp.cjs:68:33: 68 │ "packageDependencies": [ ╵ ^
You can mark the path "react-dom/client" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "react/jsx-runtime"
app/entry.client.tsx:10:8: 10 │ <RemixBrowser /> ╵ ^
The Yarn Plug'n'Play manifest forbids importing "react" here because it's not listed as a dependency of this package:
../../.pnp.cjs:68:33: 68 │ "packageDependencies": [ ╵ ^
You can mark the path "react/jsx-runtime" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@remix-run/react"
app/root.tsx:9:7: 9 │ } from "@remix-run/react"; ╵ ~~~~~~~~~~~~~~~~~~
The Yarn Plug'n'Play manifest forbids importing "@remix-run/react" here because it's not listed as a dependency of this package:
../../.pnp.cjs:68:33: 68 │ "packageDependencies": [ ╵ ^
You can mark the path "@remix-run/react" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "react/jsx-runtime"
app/root.tsx:20:6: 20 │ <head> ╵ ^
The Yarn Plug'n'Play manifest forbids importing "react" here because it's not listed as a dependency of this package:
../../.pnp.cjs:68:33: 68 │ "packageDependencies": [ ╵ ^
You can mark the path "react/jsx-runtime" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "react/jsx-runtime"
app/routes/index.tsx:4:6: 4 │ <h1>Welcome to Remix</h1> ╵ ^
The Yarn Plug'n'Play manifest forbids importing "react" here because it's not listed as a dependency of this package:
../../.pnp.cjs:68:33: 68 │ "packageDependencies": [ ╵ ^
You can mark the path "react/jsx-runtime" as external to exclude it from the bundle, which will remove this error.
Build failed with 7 errors: app/entry.client.tsx:1:29: ERROR: Could not resolve "@remix-run/react" app/entry.client.tsx:2:44: ERROR: Could not resolve "react" app/entry.client.tsx:3:28: ERROR: Could not resolve "react-dom/client" app/entry.client.tsx:10:8: ERROR: Could not resolve "react/jsx-runtime" app/root.tsx:9:7: ERROR: Could not resolve "@remix-run/react" ... Error at Object.onCompileFailure (/Users/thaddeuskrugman/Desktop/remix-test/node_modules/@remix-run/dev/dist/cli/commands.js:179:13) at Object.compile (/Users/thaddeuskrugman/Desktop/remix-test/node_modules/@remix-run/dev/dist/compiler/remixCompiler.js:33:134) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async Object.build (/Users/thaddeuskrugman/Desktop/remix-test/node_modules/@remix-run/dev/dist/compiler/build.js:33:3) at async Object.build (/Users/thaddeuskrugman/Desktop/remix-test/node_modules/@remix-run/dev/dist/cli/commands.js:174:3) at async Object.run (/Users/thaddeuskrugman/Desktop/remix-test/node_modules/@remix-run/dev/dist/cli/run.js:448:7)
I am getting this exact issue. Did you figure this out?