I try to use typescript 2.2.2 and babel loaders in webpack 2 and exclude node_modules, but when try webpack command still get errors from angular 4.0.0 which is in node_modules.
webpack.congfig.js:
var path = require('path');
var webpack = require('webpack');
var PROD = true;
module.exports = {
entry: path.join(__dirname, 'ng2', 'src','index.js'),
output: {
path: path.join(__dirname, 'ng2', 'dist'),
filename: 'vendorNG2.js'
},
devtool: 'eval',
resolve: {
extensions: [".tsx", ".ts", ".js"]
},
watch: true,
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
exclude: [/node_modules/],
},
{
test: /\.js$/,
exclude: [/node_modules/],
use: {
loader: "babel-loader?cacheDirectory=true",
options: {
presets: ['es2015']
}
}
},
]
},
plugins: PROD ? [
new webpack.optimize.UglifyJsPlugin({
compress: { warnings: false }
})
] : []
}
after webpack --progress command:
...
ERROR in /home/user/Projects/project/front/node_modules/angular2/src/facade/lang.d.ts
(13,17): error TS2693: 'Map' only refers to a type, but is being used as a value here.
ERROR in /home/user/Projects/project/front/node_modules/angular2/src/facade/lang.d.ts
(14,17): error TS2693: 'Set' only refers to a type, but is being used as a value here.
ERROR in ./ng2/src/app/main.ts
(19,14): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.
You can see errors come from node_modules.
tsconfig.json v1:
{
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"noImplicitAny": true,
"module": "commonjs",
"target": "es5",
"jsx": "react",
"allowJs": true
}
}
tsconfig.json v2:
{
"compilerOptions": {
"outDir": "./ng2/dist/",
"sourceMap": true,
"noImplicitAny": true,
"module": "commonjs",
"target": "es5",
"jsx": "react",
"type":[],
"allowJs": true
},
"exclude": [
"node_modules"
]
}
v2 errors:
ERROR in /home/user/Projects/project/front/admin/tsconfig.json
error TS5023: Unknown compiler option 'type'.
@ ./ng2/src/index.js 8:0-21
ERROR in ./ng2/src/app/main.ts
Module build failed: error while parsing tsconfig.json
@ ./ng2/src/index.js 8:0-21
tsconfig.js v3 add ("experimentalDecorators": true) some errors gone:
{
"compilerOptions": {
"outDir": "./ng2/dist/",
"sourceMap": true,
"noImplicitAny": true,
"module": "commonjs",
"target": "es5",
"jsx": "react",
"experimentalDecorators": true,
"allowJs": true
},
"exclude": [
"node_modules"
]
}
v3 errors :
... ERROR in /home/user/Projects/project/front/node_modules/angular2/src/facade/lang.d.ts (13,17): error TS2693: 'Map' only refers to a type, but is being used as a value here.
ERROR in /home/user/Projects/project/front/node_modules/angular2/src/facade/lang.d.ts (14,17): error TS2693: 'Set' only refers to a type, but is being used as a value here.
Have you added exclude node_modules to your tsconfig?
{
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"noImplicitAny": true,
"module": "commonjs",
"target": "es5",
"jsx": "react",
"allowJs": true
},
"exclude": [
"node_modules"
]
}
Also, you aren't specifying which versions of Typescript and Angular you are using.
Edit:
You updated your question to specify that you're using Angular 4 but your updated errors show a node_modules/angular2/ folder which doesn't seem right. Before going further, try deleting your node_modules folder and run npm install again.
Otherwise it looks like you're having a typings issue. Do you have any @types installed?
Here is an example of how my tsconfig.json is setup:
{
"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [ "es2015", "dom" ],
"removeComments": false,
"noImplicitAny": false,
"types": [ "jasmine", "lodash", "core-js" ],
"typeRoots": [
"../node_modules/@types"
]
},
"exclude": [
"node_modules",
"wwwroot",
"temp"
]
}
My node_modules folder is in the parent directory, so I specify that in the typeRoots. With that I also have the following types installed as well:
"@types/core-js": "0.9.37",
"@types/jasmine": "2.5.43",
"@types/lodash": "4.14.55",
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With