默认节点包版本集无法构建,但修改后的版本集无效

时间:2018-03-14 06:43:38

标签: node.js typescript version

GitHub Issue
这个问题与更新版本的ts-loader抛出错误有关,当你从版本" ^ 4.0.1"降级tsloader时都会解决这个问题。到" ^ 3.5.0"

我使用backpack + typescript编写测试项目并使用以下命令安装节点包:

npm install -D jshint ts-loader typescript backpack-core copy-webpack-plugin nodemon  
npm install -S asciify  

经过一些修改后,会产生以下package.json:

{
  "name": "myTestProject",
  "version": "0.0.1",
  "description": "learn",
  "private": true,
  "scripts": {
    "start": "node ./prd/main.js",
    "dev": "backpack dev",  
    "build": "backpack build"
  },
  "license": "MIT",
  "devDependencies": {
    "backpack-core": "^0.7.0",
    "copy-webpack-plugin": "^4.5.1",
    "jshint": "^2.9.5",
    "nodemon": "^1.17.2",
    "ts-loader": "^4.0.1",
    "typescript": "^2.7.2"
  },
  "dependencies": {
    "asciify": "^1.3.5"
  }
}

但在使用npm run build im构建时收到错误:

> myTestProject@0.0.1 build /home/myUser/myProjectFolder/myTestProject
> backpack build

 ERROR  Failed to compile with 1 errors00:34:00

 error  in ./src/main.ts

Module build failed: TypeError: Cannot read property 'afterCompile' of undefined
    at successfulTypeScriptInstance (/home/myUser/myProjectFolder/myTestProject/node_modules/ts-loader/dist/instances.js:147:28)
    at Object.getTypeScriptInstance (/home/myUser/myProjectFolder/myTestProject/node_modules/ts-loader/dist/instances.js:48:12)
    at Object.loader (/home/myUser/myProjectFolder/myTestProject/node_modules/ts-loader/dist/index.js:16:41)

 @ multi ./src/main.ts


npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! myTestProject@0.0.1 build: `backpack build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the myTestProject@0.0.1 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/myUser/.npm/_logs/2018-01-01T01_01_01_010Z-debug.log

要解决此问题,我需要重新安装删除node_modules文件夹并替换package.json:

{
  "name": "myTestProject",
  "version": "0.0.1",
  "description": "learn",
  "private": true,
  "scripts": {
    "start": "node ./prd/main.js",
    "dev": "backpack dev",
    "build": "backpack build"
  },
  "license": "MIT",
  "devDependencies": {
    "backpack-core": "^0.5.0",
    "copy-webpack-plugin": "^4.5.0",
    "jshint": "^2.9.5",
    "ts-loader": "^3.5.0",
    "typescript": "^2.7.2"
  },
  "dependencies": {
    "@types/asciify": "^1.3.29",
    "asciify": "^1.3.5"
  }
}

添加了包nodemon以尝试解决但没有效果。 我的问题是我在经过大量工作后发现了这套工作包的版本,但它可以在另一个场景中发生,我将没有那么多时间来修复,甚至可以完全理解这里发生的事情。
npm list输出了几个问题。 任何人都可以解释为什么会发生这种情况,如果有某种方法可以避免这种类型的问题,我无法猜测每次输入npm install命令时都要使用每个包的工作版本。

1 个答案:

答案 0 :(得分:1)

ts-loader 4.0符合webpack突破性更改的重大变化。我怀疑你是在碰撞那个。我建议您使用3.5作为工作流程。