【发布时间】:2019-03-21 23:21:00
【问题描述】:
我需要在我的打字稿项目中使用lodash-es,但我无法正确配置它,它总是报SyntaxError: Unexpected identifier之类的错误
hello.ts
import upperCase from 'lodash-es/upperCase'
console.log('Hello ' + upperCase('typescript') + '!');
package.json
{
"scripts": {
"demo": "ts-node hello.ts"
},
"dependencies": {
"lodash-es": "4.17.11"
},
"devDependencies": {
"@types/lodash-es": "4.17.1",
"ts-node": "7.0.0",
"typescript": "3.0.1"
}
}
tsconfig.json
{
"compilerOptions": {
"target": "es6",
"module": "commonjs"
}
}
运行ts-node hello.ts时,报错如下:
/typescript-use-lodash-es-demo/node_modules/lodash-es/upperCase.js:1
(function (exports, require, module, __filename, __dirname) { import createCompounder from './_createCompounder.js';
^^^^^^^^^^^^^^^^
SyntaxError: Unexpected identifier
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
我还为此问题设置了一个小演示,如果需要,您可以克隆并尝试:https://github.com/freewind-demos/typescript-use-lodash-es-demo
一个相关的问题是使用 lodash-es 和 babel:How to configure babel correctly to use lodash-es?。由于我不确定他们有完全相同的原因,所以我在这里要求打字稿
【问题讨论】:
标签: typescript ts-node lodash