考慮到這些檔案:
mymodule.mjs
export const answer =42
tsconfig.json
{
"compilerOptions": {
"rootDir": "src",
"outDir": "lib",
"baseUrl": "。",
"skipLibCheck": true,
"target": "es6",
"模塊": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"declarationMap": true,
"inlineSources": false,
"宣告": 真,
"stripInternal": true,
"lib": []。
"es2016",
"dom"
],
"strict": true,
"noImplicitReturns": true,
"noUnusedLocals": true
},
"include": []。
"src"/span>
]
}
軟體包.json:
{
"name": "deleteme2",
"version": "0.1.0",
"private": true,
"dependencies": {}。
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0"、
"@testing-library/user-event": "^12.1.10"、
"@types/jest": "^26.0.15"、
"@types/node": "^12.0.0",
"@types/react": "^17.0.0"、
"@types/react-dom": "^17.0.0",/span>
"reaction": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"typescript": "^4.1.2",
"web-vitals": "^1.0.1"/span>
},
"scripts": {
"compile": "tsc",
"build": "yarn run compile",
"start": "node lib/server.mjs",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": []。
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": []。
">0.2%",
"不死",
"not op_mini all"/span>
]/span>,
"development": []。
"最后1個chrome版本",
"最后1個火狐版本",
"最后1個Safari版本"/span>
]
}
}
它的編譯成功率為:
$ yarn run build
然而,當我試圖啟動它時,yarn run start我得到了錯誤:
$ node lib/server.mjs.
internal/modules/cjs/loader.js: 892
throw err;
^
Error。Cannot find module 'C:Usersuser1Desktopdeleteme2libserver.mjs'。
在Function.Module._resolveFilename(internal/modules/cjs/loader. js:889:15)
在Function.Module._load(internal/modules/cjs/loader. js:745:27)
在Function.executeUserEntryPoint [as runMain] (internal/modules/run_main. js:76:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND'。
requireStack: []
}
error Command failed with exit code 1.。
為什么輸出檔案夾中沒有server.mjs?
uj5u.com熱心網友回復:
因為你試圖用tsc編譯.mjs檔案。
tsc只支持.ts,.tsx檔案,因為它是用來將TypeScript編譯為JavaScript的。所以你不能用它來編譯.mjs,.js或任何其他檔案型別。
如果你把你的檔案改為mymodule.ts并把它放在src/里面(因為你只在你的tsconfig.json中包括src),那么它應該如期作業。在這種情況下,輸出檔案將在.js中,所以你需要運行node lib/myModule.js來代替。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/331050.html
標籤:
上一篇:“處理程式‘lambda_handler’在模塊‘lambda_function’上丟失”,“errorType”:“Runtime.HandlerNotFound”[ERROR]NameError:
