cordova创建项目失败,但它可以运行或构建

时间:2017-05-18 02:33:31

标签: node.js cordova

我尝试重新安装cordova并重新安装系统,但它没有用。我的cordova版本是7.0.1,节点版本是v6.10.3,npm版本是3.10.10。新项目错误的代码如下。


 - E:\cordovaProject>cordova create myapp  com.mu myapp -d  Using
   detached cordova-create  Creating a new cordova project.  Copying
   assets."  Using cordova-fetch for
   C:\Users\Administrator\AppData\Roaming\npm\node_modules\
   cordova\node_modules\_cordova-app-hello-world@3.12.0@cordova-app-hello-world\ind
   ex.js  Running command: cmd "/s /c ""C:\Program Files\nodejs\npm.cmd"
   install C:\Users\
   Administrator\AppData\Roaming\npm\node_modules\cordova\node_modules\_cordova-app
   -hello-world@3.12.0@cordova-app-hello-world\index.js"" Command finished with error code 4294963238: cmd /s /c ""C:\Program
   Files\nodejs \npm.cmd" install
   C:\Users\Administrator\AppData\Roaming\npm\node_modules\cordov
   a\node_modules\_cordova-app-hello-world@3.12.0@cordova-app-hello-world\index.js"

   Error: Uncaught, unspecified "error" event. (  Error from Cordova
   Fetch: Error: cmd: Command failed with exit code 4294963238 Error
   output: npm ERR! not a package
   C:\Users\Administrator\AppData\Roaming\npm\node_modules\c
   ordova\node_modules\_cordova-app-hello-world@3.12.0@cordova-app-hello-world\inde x.js npm ERR! addLocal Could not install
   C:\Users\Administrator\AppData\Roaming\npm\n
   ode_modules\cordova\node_modules\_cordova-app-hello-world@3.12.0@cordova-app-hel
   lo-world\index.js npm ERR! path
   C:\Users\Administrator\AppData\Local\Temp\npm-8056-980eaa3d\unpack
   -8e52606f\package.json npm ERR! code ENOENT npm ERR! errno -4058 npm ERR! syscall open npm ERR! enoent ENOENT: no such file or directory,
   open 'C:\Users\Administrator\
   AppData\Local\Temp\npm-8056-980eaa3d\unpack-8e52606f\package.json'
   npm ERR! enoent This is most likely not a problem with npm itself npm
   ERR! enoent and is related to npm not being able to find a file. npm
   ERR! enoent

   npm ERR! A complete log of this run can be found in: npm ERR!    
   C:\Users\Administrator\AppData\Roaming\npm-cache\_logs\2017-05-18T0
   2_13_23_845Z-debug.log)

3 个答案:

答案 0 :(得分:0)

嘿,我遇到了与你上面描述的问题相同的问题。 我用答案here解决了这个问题。

答案 1 :(得分:0)

当我尝试添加插件时,我在Windows中遇到了同样的问题。要解决此问题,请删除node_modules并重试该命令以添加插件。这解决了我的问题。

答案 2 :(得分:0)

  1. 打开文件C:\Users\YOUR-PC-USERNAME\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\cordova-create\node_modules\cordova-fetch\index.js
  2. 找到文本fetchArgs.push(target);,然后在此行之前插入以下代码:
    if(fs.existsSync(target) && fs.statSync(target).isFile()){
        target = require(target).dirname
    }
    

软件包版本列表:

  1. cordova:8.1.2
  2. cordova-app-hello-world:3.12.0
  3. cordova-create:1.1.2
  4. cordova-fetch:1.3.1

这对我有用。