我正在尝试使用mikro-orm CLI,但遇到ts-node错误:
$ npx mikro-orm debug
npx: installed 280 in 14.531s
(node:19228) UnhandledPromiseRejectionWarning: Error: Cannot find module 'ts-node'Require stack:
- C:\tmp\nodejs\npm-cache\_npx\19228\node_modules\mikro-orm\dist\cli\CLIHelper.js
- C:\tmp\nodejs\npm-cache\_npx\19228\node_modules\mikro-orm\dist\cli.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1080:15)
at Function.Module._load (internal/modules/cjs/loader.js:923:27)
at Module.require (internal/modules/cjs/loader.js:1140:19)
at require (internal/modules/cjs/helpers.js:75:18)
我的package.json具有以下内容:
"scripts": {
"watch": "tsc -w",
"dev": "nodemon dist/index.js",
"start": "node dist/index.js",
"dev2": "nodemon --exec ts-node src/index.ts",
"start2": "ts-node src/index.ts",
"test": "echo \"Error: no test specified\" && exit 1",
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/node": "^14.6.3",
"nodemon": "^2.0.4",
"ts-node": "^9.0.0",
"typescript": "^4.0.2"
},
"dependencies": {
"@mikro-orm/cli": "^4.0.0-alpha.0",
"@mikro-orm/core": "^4.0.0-alpha.0",
"@mikro-orm/migrations": "^4.0.0-alpha.0",
"@mikro-orm/postgresql": "^4.0.0-alpha.0",
"pg": "^8.3.3"
},
"mikro-orm": {
"useTsNode": true,
"configPaths": [
"./src/mikro-orm.config.ts",
"./dist/mikro-orm.config.js"
]
}
我正在使用'watch'和'dev'脚本当前运行,ts-node也可以与脚本'start2'< / strong>
我的文件夹结构是:https://i.stack.imgur.com/7BGMT.png
这对我来说是新的,我无法弄清楚问题出在哪里。你知道会是什么吗?
谢谢!
答案 0 :(得分:0)
@MartinAdámek回答“将所有软件包升级到最新版本,您使用的是第一个alpha版本,最新版本是rc.6”
答案 1 :(得分:0)
真正的答案应该是package.json中的mikro-orm配置说useTsNode:true。将其更改为false,它不会抱怨缺少ts-node。