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

Getting "Can't resolve 'module'" error on Next.js project #11

Open
Dentrax opened this issue Feb 22, 2022 · 2 comments
Open

Getting "Can't resolve 'module'" error on Next.js project #11

Dentrax opened this issue Feb 22, 2022 · 2 comments

Comments

@Dentrax
Copy link

Dentrax commented Feb 22, 2022

$ npm install --save optional-require
import { optionalRequire } from "optional-require";

const foo = optionalRequire("bar.json");

Any finally:

error - ./node_modules/require-at/create-require.js:3:0
Module not found: Can't resolve 'module'

Import trace for requested module:
./node_modules/require-at/require-at.js
./node_modules/optional-require/dist/index.js
./node_modules/optional-require/index.js
Node v17.4.0

Any ideas on this? @jchip 🤔

@jchip
Copy link
Owner

jchip commented Feb 24, 2022

this is for working with the native node.js require only. In next.js it's using webpack to compile and bundle .js for the browser, so it wouldn't work there.

@inspiraller
Copy link

inspiraller commented Jan 22, 2023

I have just followed these instructions to set up a nextjs project and I get the same error.

1. Have vscode open with terminal gitbash open - pointing at the c:\apps
2. Running create nextjs project from cmder.

steps (From cmder):
2.1 npx create-next-app@latest projectname --typescript

Need to install the following packages:
create-next-app
Ok to proceed? (y) y
√ Would you like to use ESLint with this project? ... No / Yes
√ Would you like to use src/ directory with this project? ... No / Yes
√ Would you like to use experimental app/ directory with this project? ... No / Yes
√ What import alias would you like configured? ... @/*

  1. cd projectname
  2. npm run dev

same error
Import trace for requested module:
./node_modules/next/dist/shared/lib/router/utils/is-bot.js
./node_modules/next/dist/shared/lib/router/router.js
./node_modules/next/dist/client/router.js
./node_modules/next/dist/client/dev/on-demand-entries-client.js

./node_modules/next/dist/shared/lib/router/utils/is-dynamic.js
There are multiple modules with names that only differ in casing.
This can lead to unexpected behavior when compiling on a filesystem with other case-semantic.
Use equal casing. Compare these module identifiers:

  • c:\apps\projectname\node_modules\next\dist\compiled@next\react-refresh-utils\dist\loader.js!c:\apps\projectname\node_modules\next\dist\build\webpack\loaders\next-swc-loader.js??ruleSet[1].rules[3].oneOf[2].use[1]!C:\apps\projectname\node_modules\next\dist\shared\lib\router\utils\is-dynamic.js
    Used by 4 module(s), i. e.

I found the solution:
First when creating the project with
npm run dev
I need to do it from vscode
I think there is something in nextjs which recognises the a temporary directory from vscode has been opened and it expects the command coming from that.

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

3 participants