繁体   English   中英

npm 错误! notarget 找不到与 type@module 匹配的版本

[英]npm ERR! notarget No matching version found for type@module

每当我使用 docker 构建时,我都会遇到这个问题。 我有一个 package.json,在“devDependencies”中带有“type”:“module”,如果删除“type”:“module”,我可以使用 docker 构建。 但是应用程序找不到 index.ejs 文件,所以我有点需要保留“type:module”。 有什么好主意吗?

{
    "name": "mediasoup-custom",
    "version": "1.0.0",
    "description": "",
    "main": "app.js",
    "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node src/app.js",
    "mon": "nodemon src/app.js",
    "watch": "watchify public/index.js -o public/bundle.js -v",
    "type": "module"
     },
     "author": "",
     "license": "ISC",
    "dependencies": {
    "body-parser": "^1.19.0",
    "ejs": "^3.1.6",
    "express": "^4.17.1",
    "httpolyglot": "^0.1.2",
    "mediasoup": "^3.7.1",
    "mediasoup-client": "^3.6.37",
    "mongoose": "^5.12.10",
    "protoo-client": "^4.0.4",
    "protoo-server": "^4.0.4",
    "react": "^17.0.2",
    "request": "^2.88.2",
    "socket.io": "^2.3.0"
    
     },
    "devDependencies": {
    "@babel/cli": "^7.14.3",
    "@babel/core": "^7.14.3",
    "type": "module"
      },
      "engines": {
      "node": "12.19.0"
  }
}

 > [ 6/10] RUN npm install:
 #11 1.042 npm WARN read-shrinkwrap This version of npm is compatible with 
 lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll 
 try to do my best with it!
 #11 2.810 npm ERR! code ETARGET
 #11 2.817 npm ERR! notarget No matching version found for type@module.
 #11 2.818 npm ERR! notarget In most cases you or one of your dependencies are 
 requesting
 #11 2.818 npm ERR! notarget a package version that doesn't exist.
 #11 2.818 npm ERR! notarget 
 #11 2.818 npm ERR! notarget It was specified as a dependency of 'app'
 #11 2.818 npm ERR! notarget 
 #11 2.826 
 #11 2.826 npm ERR! A complete log of this run can be found in:
 #11 2.826 npm ERR!     /root/.npm/_logs/2021-09-09T22_41_21_395Z-debug.log
 ------
 executor failed running [/bin/sh -c npm install]: exit code: 1

好的,所以我找到了解决办法。

我创建了一个可选的依赖部分并添加了“类型:模块”。

之后我能够部署到 Droplet。

"optionalDependencies": {
"type": "module"
},

这简直是胡说八道: type不是 package 的名称, module不是有效版本。 这些都不在依赖部分; "type": "module"应该在 package.json 中的顶层。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM