我遇到以下问题:我导入了一个上传到npm的OpenDolphin库,该库似乎在TS中实现,带有一个带有所有导出声明的main.js。
我尝试在我的TypeScript代码中使用库,如下所示:
import { OpenDolphin, ClientDolphin } from 'openDolphin/main';然后我尝试使用这个:
let builder = OpenDolphin.makeDolphin();在将此转换为ES5之后,我在chrome中出现以下错误:
SyntaxError: Unexpected token export看来,包含出口报表的图书馆的main.js,
以某种方式不处理,只是附加到最终的dist文件:
//snipped from the final js file
/* 469 */
/***/ function(module, exports) {
export { Attribute } from './js/dolphin/Attribute';
...all the rest of OpenDolphin export statements.
}对我来说,作为一个TS(JS工具链)初学者,看起来,这个库是
以某种方式没有正确处理/转发或类似的东西。
我的设置:
的package.json:
{
"name": "FrontendExample",
"version": "1.0.0",
"private": false,
"description": "",
"author": "",
"license": "MIT",
"preferGlobal": false,
"scripts": {
"build": "webpack --display-error-details"
},
"dependencies": {
"@cycle/rxjs-run": "3.2",
"@cycle/dom": "12.2.0",
"@cycle/isolate": "1.4.x",
"OpenDolphin": "1.0.1",
"core-js": "2.4.1",
"rxjs": "5.0.1",
"ts-helpers": "1.1.2",
"xstream": "9.2"
},
"devDependencies": {
"@types/node": "6.0.42",
"ts-node": "1.2.1",
"tslint": "4.1.1",
"typescript": "2.0.3",
"typings": "2.1.0",
"ts-loader": "^0.8.2",
"webpack": "^1.13.1"
}
}webpack.config.js:
var webpack = require('webpack');
module.exports = {
entry: './src/app.ts',
output: {
filename: './dist/main.js'
},
// Turn on sourcemaps
devtool: 'source-map',
resolve: {
extensions: ['', '.webpack.js', '.web.js', '.ts', '.js']
},
// Add minification
// plugins: [
// new webpack.optimize.UglifyJsPlugin()
// ],
module: {
loaders: [
{ test: /\.ts$/, loader: 'ts' }
]
}
};更新1:
只有导入
import { OpenDolphin, ClientDolphin, ClientPresentationModel, ClientAttribute, Tag } from 'openDolphin';没有帮助,同样的错误依然存在。但是,Intellij将另外在TS-File红色中标记导入。
我...不确定OpenDolphin npm包是否正确:它只包含一个main.js,main.d.ts,一个没有browserify,babelify或其他内容的package.json,一个包含所有* .ts文件...?