[英]unexpected identifier in .d.ts file
我正在使用帶有以下構建說明的typescript。
"build:types": "tsc --emitDeclarationOnly",
"build:js": "babel src --out-dir lib --extensions \".ts,.tsx\" --source-maps inline",
"start": "npm run build:types && npm run build:js && node ./lib/bin/www.js"
我的一個.ts
文件導入了mongoose。 運行npm start
出現以下錯誤。 在.d.ts
文件中
\lib\models\v1\collection1.model.d.ts:1
(function (exports, require, module, __filename, __dirname) { import mongoose from 'mongoose';
^^^^^^^^
SyntaxError: Unexpected identifier
注意“@ types / mongoose”和“mongoose”已經是依賴。
collection1.model.d.ts的內容如下。 這是由tsc --emitDeclarationOnly
生成的
import mongoose from 'mongoose';
declare const _default: mongoose.Model<mongoose.Document, {}>;
export default _default;
tsconfig.json
{
"compilerOptions": {
"target": "es2015",
"module": "commonjs",
"declaration": true,
"outDir": "./lib",
"strict": false,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
},
"include": ["src"]
}
.babelrc
{
"presets": [
"@babel/env",
"@babel/typescript"
],
"plugins": [
"@babel/proposal-class-properties",
"@babel/proposal-object-rest-spread",
"@babel/transform-runtime"
]
}
所以問題是我應該沒有使用babel而是簡單地使用tsc來生成所有代碼。 謝謝所有有幫助的人
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.