我试图使用mikro orm CLI,但遇到了一个ts节点错误:
$ npx mikro-orm debug
npx: installed 280 in 14.531s
(node:19228) UnhandledPromiseRejectionWarning: Error: Cannot find module 'ts-node'Require stack:
- C:tmpnodejsnpm-cache_npx19228node_modulesmikro-ormdistcliCLIHelper.js
- C:tmpnodejsnpm-cache_npx19228node_modulesmikro-ormdistcli.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'start2'脚本也可以正常工作
我的文件夹结构是:https://i.stack.imgur.com/7BGMT.png
这对我来说是新的,我不知道问题出在哪里。你知道可能是什么吗?
谢谢!
@MartinAdámek回答:"将所有软件包升级到最新版本,您正处于第一个alpha版本,最新版本为rc.6'
真正的答案应该是package.json中的mikro-orm配置显示useTsNode:true。将其更改为false,它就不会抱怨缺少ts节点。