node.js - לא מצליח להריץ את הפרויקט שלי ב-nodejs ו-typescript, ואני מקבל את השגיאה ".ts כהרחבת קובץ לא מוכרת"
אני עכשיו מקבל את השגיאה הזו:
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts"
זה קרה לאחר שהוספתי "type": "module" ל-package.json
package.json
{
"name": "Test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"watch": "tsc -w",
"dev": "tsc && concurrently \"tsc -w\" \"nodemon\""
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"typeorm": "^0.2.31"
},
"devDependencies": {
"@types/node": "^14.14.25",
"ts-node": "^9.1.1",
"typescript": "^4.1.4"
},
"type": "module"
}
tsconfig.json
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"lib": [
"dom",
"es6",
"es2017",
"esnext.asynciterable"
],
"sourceMap": true,
"outDir": "./dist",
"moduleResolution": "node",
"removeComments": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"resolveJsonModule": true,
"baseUrl": "."
},
"exclude": [
"node_modules"
],
"include": [
"./src/**/*.tsx",
"./src/**/*.ts"
]
}
ואני מריץ גרסה nodejs - v14.16.0 ו-typescript - v4.1.4
תשובה #1
למיטב ידיעתי allowSyntheticDefaultImports ו-esModuleInterop הם הדדיים ולא יכולים לפעול יחד. לא יודע אם זו הבעיה האמיתית, אפילו. גם הייתי מסיר את הבלוקים של include ו-exclude, במקרה הזה אני חושב שהם לא עושים כלום.
ודא פעמיים שאתה דורש את המודול בתיקיית dist.