Issue
Every time I use nodemon with npm run start, I encounter the error message "Error: Cannot find module 'Test'". Similarly, when I build files using npm run build and try to run ./dist/index.js, I face the same issue.
It seems that the require path in ./dist/index.js is not being recognized correctly.
I am unsure about which configuration settings need to be adjusted, so I am reaching out for assistance.
If you have dealt with a similar problem before, I would greatly appreciate it if you could share your solutions with me. Thank you!
Code Snippets
./src/index.ts
import Test from 'Test';
const test = new Test();
./src/Test/index.ts
export default class Test {
constructor () {
console.log('Test');
}
}
./dist/index.js
"use strict";
var _Test = _interopRequireDefault(require("Test"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var test = new _Test.default();
./package.json
{
"version": "1.0.0",
"description": "",
"scripts": {
"build": "babel ./src --extensions .ts,.js --out-dir ./dist",
"start": "nodemon ./src --exec babel-node --extensions .ts,.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/cli": "^7.0.0-beta.47",
"@babel/core": "^7.0.0-beta.47",
"@babel/node": "^7.0.0-beta.47",
"@babel/plugin-proposal-class-properties": "^7.0.0-beta.47",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0-beta.47",
"@babel/polyfill": "^7.0.0-beta.47",
"@babel/preset-env": "^7.0.0-beta.47",
"@babel/preset-typescript": "^7.0.0-beta.47",
"cross-env": "^5.1.5",
"nodemon": "^1.17.4"
}
}
./tsconfig.json
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"lib": ["ES2015", "ES2017", "DOM"],
"noEmit": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"module": "esnext",
"moduleResolution": "node",
"paths": { "*":["node_modules/*", "src/*"] },
"pretty": true,
"strictNullChecks": true,
"target": "es5",
"typeRoots": ["./node_modules/@types"]
}
}
./.babelrc
{
presets: ['@babel/preset-env', '@babel/preset-typescript'],
plugins: ['@babel/plugin-proposal-class-properties', '@babel/plugin-proposal-object-rest-spread']
}