幾天前我有這個錯誤。有幾個類似的問題,但沒有答案解決我的問題。
它發生在我跑步時npm run start,跑步后npm run build
為什么npm run start運行帶有.ts擴展名的檔案ormconfig.ts?這是正確的行為嗎?不應該ormconfig.js跑嗎?
- 完整的錯誤資訊
C:\Users\franc\Code\f5\server\ormconfig.ts:1
從“./src/entities/Booking”匯入 { Booking }
SyntaxError: 不能在模塊外使用 import 陳述句 在 Object.compileFunction (node:vm:352:18) 在 wrapSafe (node:internal/modules/cjs/loader:1031:15) 在 Module._compile (node:internal/modules/cjs/loader:1065:27) 在Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10) 在 Module.load (node:internal/modules/cjs/loader:981:32) 在 Function.Module._load (node :internal/modules/cjs/loader:822:12) 在 Module.require (node:internal/modules/cjs/loader:1005:19) 在 require (node:internal/modules/cjs/helpers:102:18) 在連接選項閱讀器。(C:\Users\franc\Code\f5\server\node_modules\typeorm\connection\ConnectionOptionsReader.js:120:46) 在步驟 (C:\Users\franc\Code\f5\server\node_modules\tslib\tslib. js:143:27) 在 Object.next (C:\Users\franc\Code\f5\server\node_modules\tslib\tslib.js:124:57) 在 C:\Users\franc\Code\f5\server\節點模塊\tslib\tslib.js:117:75 at new Promise () at __awaiter (C:\Users\franc\Code\f5\server\node_modules\tslib\tslib.js:113:16) at ConnectionOptionsReader.load (C:\Users\franc\Code\f5\ server\node_modules\typeorm\connection\ConnectionOptionsReader.js:92:38) 在 ConnectionOptionsReader。(C:\Users\franc\Code\f5\server\node_modules\typeorm\connection\ConnectionOptionsReader.js:34:55)
- 包.json

- tsconfig.json

- 專案結構

PS: 這是我在平臺上的第一個問題,如果有遺漏的資料告訴我!對不起我的英語:)
uj5u.com熱心網友回復:
移動ormconfig.ts到您的src檔案夾(必要時更改匯入),然后添加include后面compilerOptions的內容以包含src. exclude使用node_modules 和測驗也是一個好主意:
{
"compilerOptions": { ... },
"include": ["src/**/*.ts"],
"exclude": ["node_modules", "tests"]
}
這可能是因為 TypeScript 在編譯輸出中包含了 ormconfig.ts:正如您在構建檔案夾中看到的那樣,有一個 index.js 和 ormconfig.js 和重復src檔案夾。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/428580.html
上一篇:為什么打字稿值變成“任何”型別
