Running a small express server and encountering an issue in my bin/www.ts
where I import my app.ts file like so:
import app from '../app';
After building the project into JavaScript using: tsc --project ./
and running it with nodemon ./build/bin/www
, an error appears in the console:
internal/process/esm_loader.js:74
internalBinding('errors').triggerUncaughtException(
^
Error [ERR_MODULE_NOT_FOUND]:
Cannot find module '/Users/t86b/Desktop/Dev/Projects/TestServerProject/Server/build/app'
imported from /Users/t86b/Desktop/Dev/Projects/TestServerProject/Server/build/bin/www.js
The specified file does exist, and I've included
"type":"module"
in my package.json
. Additionally, I've removed all requires from app.ts without success. Unsure of the next steps to take. Below is a condensed version of my package.json
:
{
...
"scripts": {
"build": "tsc --project ./",
"start": "nodemon ./build/bin/www",
"start:dev": "nodemon -r ./bin/www.ts",
"tsc": "tsc",
"tsStart": "node ./build/bin/www"
},
...
"dependencies": {
...
"express": "^4.17.1",
"typescript": "^4.0.3"
},
"type": "module",
"devDependencies": {
...
"nodemon": "^2.0.7",
"ts-node": "^9.1.1"
}
}
My ts.config
:
{
"compilerOptions": {
"target": "es2017",
"module": "ESNext",
"lib": ["ES2017"],
"outDir": "./build",
"rootDir": "./",
"strict": true,
"moduleResolution": "node",
"esModuleInterop": true,
/* Advanced Options */
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
}
}
If helpful, here's a snippet of my app.ts (error-free for clarity):
import express from 'express';
import indexRouter from './routes/index';
...
let app = express();
app.use('/', indexRouter);
export default app;
Seeking guidance on resolving the issue to successfully start up the server. Any additional details needed, feel free to ask.