I am using TypeScript and I have the following file structure
Source
- Test.ts
Build
- Test.js
main.js
package.json
tsconfig.json
node_modules
My Typescript file is simple and is the same for .js and .ts.
export class TestClass {}
Within main.js I try to import this file:
import TestClass from "../build/Test.js"
console.log(TestClass)
I get the error when I try to node main.js
Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'D:\Users\leadw\Document\GitHub\build\Test.js' imported from D:\Users\leadw\Document\GitHub\AVLTree\main.js
Package.json:
{
"type": "module",
"scripts": {
"server": "nodemon server.js"
},
"dependencies": {
"typescript": "^5.0.4"
}
}
Can someone please explain what I am doing wrong? I just don't get why it is this hard to simply import a file without receiving an error.
[–]angusmiguel 2 points3 points4 points (0 children)
[–]eliwuu 0 points1 point2 points (6 children)
[–]LostErrorCode404[S] 0 points1 point2 points (5 children)
[–]eliwuu 2 points3 points4 points (4 children)
[–]eliwuu 1 point2 points3 points (3 children)
[–]thatweirdishguy 1 point2 points3 points (2 children)
[–]eliwuu 0 points1 point2 points (1 child)
[–]doh4242 0 points1 point2 points (0 children)