在我的 Node.js 项目中,我的 package.json 文件中有一个脚本,它使用 mocha 运行测试,如下所示:
"scripts": {
"test": "mocha --reporter list spec/*",
"test:cov": "istanbul cover _mocha -R spec && open coverage/lcov-report/index.html"
},
我只是尝试通过运行以下命令在我的 Windows 计算机上运行测试脚本:
npm run test
我收到以下消息:
Error: Cannot find module 'C:\Users\[User]\Projects\Leaflet-LightCluster\spec\setup'
我决定通过全局安装 mocha 来测试这是否是 mocha 的问题(即 npm install -g mocha
),当我运行“测试”脚本中包含的相同命令时,一切都运行正常。
我在工作中使用 Mac,从未遇到过此问题。事实上,我可以在 Mac 上的同一个项目上运行相同的 npm
命令,并且它可以工作。我正在我的个人 Windows 计算机上处理一些个人项目,因此认为这是 Windows 问题?
谁能验证这是一个 Windows 问题吗? 还有人遇到过这个问题并知道如何解决吗?
提前致谢!
最佳答案
这是我在本地安装了 mocha 的 Windows 和 UNIX 环境中使用的配置:
"test": "istanbul cover ./node_modules/mocha/bin/_mocha -- -R spec --full-trace --trace ./test/**/*.spec.js"
您可以在这里查看 Link通过配置,情况会更复杂,因为我需要覆盖 fork 实例。
关于node.js - Windows 上的 "npm run""cannot find module",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33161997/