-
Notifications
You must be signed in to change notification settings - Fork 275
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
ERR_MODULE_NOT_FOUND for project-level module #3163
Comments
I think file extensions are needed here: https://nodejs.org/api/esm.html#esm_mandatory_file_extensions Here is the log of something that works for me: ❯ tree .
.
├── index.js
├── modules
│ ├── map-codes.js
│ └── place-details.js
├── package.json
└── package-lock.json
1 directory, 5 files
❯ cat package.json
{
"name": "project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"type": "module",
"keywords": [],
"author": "",
"license": "ISC"
}
❯ cat package-lock.json
{
"name": "project",
"version": "1.0.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"version": "1.0.0",
"license": "ISC"
}
}
}
❯ cat index.js
import placeDetails from './modules/place-details.js';
import mapCodes from './modules/map-codes.js';
console.log(placeDetails);
console.log(mapCodes);
❯ cat modules/map-codes.js
export default 'map-codes';
❯ cat modules/place-details.js
export default 'place-details';
❯ node index.js
place-details
map-codes
Does this work for you? |
Interesting. I'll look into it tonight. I don't quite understand why I'm also getting errors when adding file existensions. Must be another problem then maybe. Also, and this is not a Node.js question I realize, but do you happen to know why VS Code would automatically not add file extensions when letting it automatically add |
I'm sorry, I don't know that about VS Code. :/ |
add js extentions on the imports line resolved the isseu for me . thanks ! |
I think I'm also hitting this same issue though it's a little weirder in the error.
|
install nodemon and in you package.json under script add this nodemon --experimental-modules --es-module-specifier-resolution=node . |
Adding the .js extension on the import lines resolves the issue. It is a weird error but I think we have to provide an extension so that nodejs can understand. |
@J-NAVEEN-KUMAR it shouldn't be needed as node checks a bunch of paths for the import including with the |
I don't understand why it will be but it worked for me |
HEY! I'VE BEEN GETTING THIS ERROR FOR ABOUT A WEEK NOW AND I DON'T UNDERSTAND HOW TO SOLVE THIS.
|
add the .js after every import , you will get your errror resolved |
Judging by the feedback, #3163 (comment) seems to be the right solution. I'm closing this as resolved for now but feel free to let me know if this still needs to stay open. |
If you used "type": "module", on package.json and then you should use import. while you are using import it required default so in router or related required file you must use like "export default serverRouter" import express from "express" serverRouter.get("/", (req, res) => { export default serverRouter |
Add this to
|
Thanks to you all, I have fixed the error... |
Hello, I have a problem with the package.json file, two days ago, and I have been suffering from the problem, and I did not find a solution to it. Can someone help and support you? ==> Build uploaded in 17s |
Before : After : Try this. |
Error: Cannot find module '/home/ubuntu/legnutz/node_modules/razorpay/index.js'. Please verify that the package.json has a valid "main" entry |
HEY! I'VE BEEN GETTING THIS ERROR FOR ABOUT A WEEK NOW AND I DON'T UNDERSTAND HOW TO SOLVE THIS. node:internal/errors:496 Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'C:\Users\Nirbhay Gupta\Desktop\Web\web_Development_Project\16_Social_Media_App\server\controllers\authController' imported from C:\Users\Nirbhay Gupta\Desktop\Web\web_Development_Project\16_Social_Media_App\server\routes\auth.js Node.js v18.18.0 |
Send me the code
…On Wed, 13 Dec 2023 at 4:12 PM nirbhay2001 ***@***.***> wrote:
HEY! I'VE BEEN GETTING THIS ERROR FOR ABOUT A WEEK NOW AND I DON'T
UNDERSTAND HOW TO SOLVE THIS.
IF ANYONE HAS ANY IDEAS PLEASE LET ME KNOW!!
node:internal/errors:496
ErrorCaptureStackTrace(err);
^
Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'C:\Users\Nirbhay
Gupta\Desktop\Web\web_Development_Project\16_Social_Media_App\server\controllers\authController'
imported from C:\Users\Nirbhay
Gupta\Desktop\Web\web_Development_Project\16_Social_Media_App\server\routes\auth.js
at new NodeError (node:internal/errors:405:5)
at finalizeResolution (node:internal/modules/esm/resolve:327:11)
at moduleResolve (node:internal/modules/esm/resolve:946:10)
at defaultResolve (node:internal/modules/esm/resolve:1132:11)
at nextResolve (node:internal/modules/esm/loader:163:28)
at ESMLoader.resolve (node:internal/modules/esm/loader:835:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
at ModuleWrap. (node:internal/modules/esm/module_job:77:40)
at link (node:internal/modules/esm/module_job:76:36) {
code: 'ERR_MODULE_NOT_FOUND'
}
Node.js v18.18.0
[nodemon] app crashed - waiting for file changes before starting...
—
Reply to this email directly, view it on GitHub
<#3163 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/A2BFZCL573EZV5TXMX3MHZDYJGBATAVCNFSM4VWHLWRKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBVGM3DOMRXHE2Q>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
This error has been resolved,recently
To give thanks response
On Wed, 13 Dec, 2023, 4:14 pm Muhammed Minhaj k, ***@***.***>
wrote:
… Send me the code
On Wed, 13 Dec 2023 at 4:12 PM nirbhay2001 ***@***.***> wrote:
> HEY! I'VE BEEN GETTING THIS ERROR FOR ABOUT A WEEK NOW AND I DON'T
> UNDERSTAND HOW TO SOLVE THIS.
> IF ANYONE HAS ANY IDEAS PLEASE LET ME KNOW!!
>
> node:internal/errors:496
> ErrorCaptureStackTrace(err);
> ^
>
> Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'C:\Users\Nirbhay
>
Gupta\Desktop\Web\web_Development_Project\16_Social_Media_App\server\controllers\authController'
> imported from C:\Users\Nirbhay
>
Gupta\Desktop\Web\web_Development_Project\16_Social_Media_App\server\routes\auth.js
> at new NodeError (node:internal/errors:405:5)
> at finalizeResolution (node:internal/modules/esm/resolve:327:11)
> at moduleResolve (node:internal/modules/esm/resolve:946:10)
> at defaultResolve (node:internal/modules/esm/resolve:1132:11)
> at nextResolve (node:internal/modules/esm/loader:163:28)
> at ESMLoader.resolve (node:internal/modules/esm/loader:835:30)
> at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
> at ModuleWrap. (node:internal/modules/esm/module_job:77:40)
> at link (node:internal/modules/esm/module_job:76:36) {
> code: 'ERR_MODULE_NOT_FOUND'
> }
>
> Node.js v18.18.0
> [nodemon] app crashed - waiting for file changes before starting...
>
> —
> Reply to this email directly, view it on GitHub
> <#3163 (comment)>,
or
> unsubscribe
> <
https://github.com/notifications/unsubscribe-auth/A2BFZCL573EZV5TXMX3MHZDYJGBATAVCNFSM4VWHLWRKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBVGM3DOMRXHE2Q>
> .
> You are receiving this because you commented.Message ID:
> ***@***.***>
>
—
Reply to this email directly, view it on GitHub
<#3163 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/A65HD6JN67F7MN4D3UI7QA3YJGBJZAVCNFSM4VWHLWRKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBVGM3DONRTGY4A>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
node:internal/modules/esm/resolve:265 I am using node V 20.12.1 but i am getting this error. Give me solutions. |
This is my project structure:
Then, in
index.js
is this:The rest of the code is not relevant. Importing modules from node_modules like (using
import ... from
) this works a charm. VS Code can navigate through these modules perfectly fine. Infact, this is how VS Code automatically added the imports.When I run the code:
The suggestion obviously doesn't work, as it suggests the file is one level up. It is not.
I've also tried
./modules/place-details.js
(adding extension) andmodules/place-details
(removing the dot-slash) and a combination. None of those work (or I wouldn't have opened this issue 😀).I'm also confused why Node.js doesn't say where it couldn't find said module, in other words, where it's been looking for it. Because it's right there. So I really don't know how else to tell Node.js where to go and grab this module. I've never had an error so confusing.
What am I missing here? I'm sure this is not a bug, seeing how mature Node.js already is.
The text was updated successfully, but these errors were encountered: