jsnlog 在安装时产生错误
jsnlog producing errors on install
我在安装和使用 jsnlog 时遇到了一些问题,如 the docs 中所述。当我尝试导入或使用该库时,我总是遇到错误。
我尝试按照文档导入库:
import { JL } from 'jsnlog'
我也试过这样包含(不知道这个风格叫什么)
import 'jsnlog';
我在 运行 npm run serve
时在控制台中得到的错误是:
ERROR in C:\Users\jeanpierreb\Documents\project\node_modules\jsnlog\Definitions\jl.d.ts
(279,10): error TS2304: Cannot find name 'r'.
ERROR in C:\Users\jeanpierreb\Documents\project\node_modules\jsnlog\Definitions\jl.d.ts
(279,12): error TS2304: Cannot find name 't'.
ERROR in C:\Users\jeanpierreb\Documents\project\node_modules\jsnlog\Definitions\jl.d.ts
(279,20): error TS2304: Cannot find name 'J'.
ERROR in C:\Users\jeanpierreb\Documents\project\node_modules\jsnlog\Definitions\jl.d.ts
(279,22): error TS2304: Cannot find name 'L'.
ERROR in ./app_ts/app.module.ts
(4,21): error TS2306: File 'C:/Users/jeanpierreb/Documents/project\node_modules/jsnlog/Definitions/jl.d.ts' is not a module.
软件版本
我包括 node/npm/angular 版本,因为我觉得问题可能出在这里。除了最新版本之外,我还没有在其他版本的节点上尝试过这个,但这是一个相当大的项目,所以我无法在不破坏应用程序的情况下轻松升级 npm 或节点
- Angular 2.1.1
- npm 4.6.1
- 节点 6.10.3
为了完整起见,这里是我的 tsconfig 和 package.json
package.json
{
"version": "1.0.0",
"name": "myproject",
"private": true,
"scripts": {
"postinstall": "typings install",
"typings": "typings",
"build": "webpack --progress",
"build-prod": "webpack -p --progress --env.prod",
"serve": "webpack --progress --colors --watch",
"start": "lite-server"
},
"dependencies": {
"@angular/common": "2.1.1",
"@angular/compiler": "2.1.1",
"@angular/core": "2.1.1",
"@angular/forms": "2.1.1",
"@angular/http": "2.1.1",
"@angular/platform-browser": "2.1.1",
"@angular/platform-browser-dynamic": "2.1.1",
"@angular/router": "3.1.1",
"@angular/upgrade": "2.1.1",
"@ngrx/core": "^1.2.0",
"@ngrx/store": "^2.2.2",
"@types/handlebars": "4.0.32",
"@types/jquery": "^2.0.34",
"@types/signalr": "^2.0.2",
"angular-in-memory-web-api": "0.3.0",
"bootstrap": "3.3.7",
"core-js": "2.4.1",
"devextreme": "16.2.3",
"devextreme-angular": "16.2.3-rc.3",
"es6-shim": "0.35.3",
"font-awesome": "4.7.0",
"jquery": "3.1.1",
"jsnlog": "^2.24.0",
"json-stringify-safe": "^5.0.1",
"jszip": "3.1.3",
"lite-server": "2.2.2",
"lodash": "4.17.4",
"moment": "2.17.1",
"ng2-ckeditor": "1.1.6",
"ng2-vis": "0.0.5",
"node-sass": "4.5.0",
"null-loader": "^0.1.1",
"reflect-metadata": "0.1.10",
"rxjs": "5.2.0",
"sass-loader": "6.0.2",
"scss-compile": "0.1.7",
"signalr": "2.2.1",
"style-loader": "0.13.2",
"ts-loader": "2.0.1",
"uglify-js": "2.8.13",
"vis": "4.18.1",
"zone.js": "0.7.7"
},
"devDependencies": {
"angular2-router-loader": "^0.3.5",
"assets-webpack-plugin": "^3.5.1",
"compression-webpack-plugin": "0.3.2",
"css-loader": "0.26.2",
"lite-server": "2.2.2",
"source-map-loader": "0.1.6",
"style-loader": "0.13.2",
"ts-loader": "2.0.1",
"typescript": "2.2.1",
"typings": "2.0.0",
"uglifyjs-webpack-plugin": "0.3.0",
"webpack": "2.2.1",
"webpack-dev-server": "2.4.1",
"webpack-merge": "4.1.0"
}
}
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"outDir": "wwwroot/app",
"rootDir": "app"
},
"compileOnSave": true,
"exclude": [
"wwwroot/node_modules",
"typings/index.d.ts",
"typings/globals/index.d.ts",
"typings/globals/jquery/index.d.ts",
"node_modules"
]
}
问题是您在 webpack 配置中使用了 ts-loader
,由于某些原因 ts-loader
无法通过将 ts-loader
替换为 [=] 来正确编译 jsnlog
14=] 将解决问题。
我在安装和使用 jsnlog 时遇到了一些问题,如 the docs 中所述。当我尝试导入或使用该库时,我总是遇到错误。
我尝试按照文档导入库:
import { JL } from 'jsnlog'
我也试过这样包含(不知道这个风格叫什么)
import 'jsnlog';
我在 运行 npm run serve
时在控制台中得到的错误是:
ERROR in C:\Users\jeanpierreb\Documents\project\node_modules\jsnlog\Definitions\jl.d.ts
(279,10): error TS2304: Cannot find name 'r'.
ERROR in C:\Users\jeanpierreb\Documents\project\node_modules\jsnlog\Definitions\jl.d.ts
(279,12): error TS2304: Cannot find name 't'.
ERROR in C:\Users\jeanpierreb\Documents\project\node_modules\jsnlog\Definitions\jl.d.ts
(279,20): error TS2304: Cannot find name 'J'.
ERROR in C:\Users\jeanpierreb\Documents\project\node_modules\jsnlog\Definitions\jl.d.ts
(279,22): error TS2304: Cannot find name 'L'.
ERROR in ./app_ts/app.module.ts
(4,21): error TS2306: File 'C:/Users/jeanpierreb/Documents/project\node_modules/jsnlog/Definitions/jl.d.ts' is not a module.
软件版本 我包括 node/npm/angular 版本,因为我觉得问题可能出在这里。除了最新版本之外,我还没有在其他版本的节点上尝试过这个,但这是一个相当大的项目,所以我无法在不破坏应用程序的情况下轻松升级 npm 或节点
- Angular 2.1.1
- npm 4.6.1
- 节点 6.10.3
为了完整起见,这里是我的 tsconfig 和 package.json
package.json
{
"version": "1.0.0",
"name": "myproject",
"private": true,
"scripts": {
"postinstall": "typings install",
"typings": "typings",
"build": "webpack --progress",
"build-prod": "webpack -p --progress --env.prod",
"serve": "webpack --progress --colors --watch",
"start": "lite-server"
},
"dependencies": {
"@angular/common": "2.1.1",
"@angular/compiler": "2.1.1",
"@angular/core": "2.1.1",
"@angular/forms": "2.1.1",
"@angular/http": "2.1.1",
"@angular/platform-browser": "2.1.1",
"@angular/platform-browser-dynamic": "2.1.1",
"@angular/router": "3.1.1",
"@angular/upgrade": "2.1.1",
"@ngrx/core": "^1.2.0",
"@ngrx/store": "^2.2.2",
"@types/handlebars": "4.0.32",
"@types/jquery": "^2.0.34",
"@types/signalr": "^2.0.2",
"angular-in-memory-web-api": "0.3.0",
"bootstrap": "3.3.7",
"core-js": "2.4.1",
"devextreme": "16.2.3",
"devextreme-angular": "16.2.3-rc.3",
"es6-shim": "0.35.3",
"font-awesome": "4.7.0",
"jquery": "3.1.1",
"jsnlog": "^2.24.0",
"json-stringify-safe": "^5.0.1",
"jszip": "3.1.3",
"lite-server": "2.2.2",
"lodash": "4.17.4",
"moment": "2.17.1",
"ng2-ckeditor": "1.1.6",
"ng2-vis": "0.0.5",
"node-sass": "4.5.0",
"null-loader": "^0.1.1",
"reflect-metadata": "0.1.10",
"rxjs": "5.2.0",
"sass-loader": "6.0.2",
"scss-compile": "0.1.7",
"signalr": "2.2.1",
"style-loader": "0.13.2",
"ts-loader": "2.0.1",
"uglify-js": "2.8.13",
"vis": "4.18.1",
"zone.js": "0.7.7"
},
"devDependencies": {
"angular2-router-loader": "^0.3.5",
"assets-webpack-plugin": "^3.5.1",
"compression-webpack-plugin": "0.3.2",
"css-loader": "0.26.2",
"lite-server": "2.2.2",
"source-map-loader": "0.1.6",
"style-loader": "0.13.2",
"ts-loader": "2.0.1",
"typescript": "2.2.1",
"typings": "2.0.0",
"uglifyjs-webpack-plugin": "0.3.0",
"webpack": "2.2.1",
"webpack-dev-server": "2.4.1",
"webpack-merge": "4.1.0"
}
}
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"outDir": "wwwroot/app",
"rootDir": "app"
},
"compileOnSave": true,
"exclude": [
"wwwroot/node_modules",
"typings/index.d.ts",
"typings/globals/index.d.ts",
"typings/globals/jquery/index.d.ts",
"node_modules"
]
}
问题是您在 webpack 配置中使用了 ts-loader
,由于某些原因 ts-loader
无法通过将 ts-loader
替换为 [=] 来正确编译 jsnlog
14=] 将解决问题。