【发布时间】:2016-08-23 03:49:21
【问题描述】:
我想将 shelljs 库包含到 Angular 2 打字稿中。我已将 shelljs.d.ts 文件包含到我的 node_modules/shelljs 库中。
我的 package.json
"name": "myproj1",
"description": "myproj1: A project",
"typings": {
"shelljs": {
"definitions": "node_modules/shelljs/shelljs.d.ts",
"source": "node_modules/shelljs/global.js"
}
},
我的 webpack.config.js
var path = require('path');
module.exports = {
entry: './app/web/boot.ts',
output: {
path: path.resolve(__dirname, "js"),
filename: "bundle.js"
},
resolve: {
extensions:['','.js','.ts']
},
module:{
loaders: [{
test: /\.ts/,
loaders: ['ts-loader'],
exclude: /node_modules/
}]
},
target: 'node'
};
我的 package.json 编译器选项:
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true
},
我的 TS 文件:
import child = require("shelljs");
somefun(){
child.exec('node --version',(code, stdout, stderr)=>{
console.log('Exit code:', code);
console.log('Program output:', stdout);
console.log('Program stderr:', stderr);
});
}
我收到错误消息“找不到模块‘shelljs’”。请帮助我将库包含在我的项目中。
【问题讨论】:
-
不知道
shell.js是如何工作的,但试试let shell = require('shelljs/global'); shell.exec(...
标签: node.js typescript angular webpack child-process