我运行时出错
yarn run package
。添加 NODE_OPTIONS="--loader ts-node/esm"
没有帮助。
我见过https://github.com/TypeStrong/ts-node/issues/1062,但我尝试了不同的
target
,但没有帮助。
package.json
:
...
"scripts": {
"build": "tsc",
"build:production": "npm run prestart && npm prune --production",
"watch": "tsc --w",
"prestart": "npm run build && func extensions install",
"start:host": "func start",
"start": "npm-run-all --parallel start:host watch",
"test": "echo \"No tests yet...\"",
"package": "gulp build && gulp package"
},
"description": "",
"devDependencies": {
"@azure/functions": "^1.0.1-beta1",
"@types/gulp": "^4.0.9",
"@types/gulp-zip": "^4.0.2",
"@types/node": "^18.11.13",
"del": "^7.0.0",
"gulp-typescript": "^6.0.0-alpha.1",
"gulp-zip": "^5.1.0",
"npm-run-all": "^4.1.5",
"ts-node": "^10.2.1",
"typescript": "^3.3.3"
},
"dependencies": {
"azure-devops-node-api": "^11.2.0",
"gulp": "^4.0.2"
},
"resolutions": {
"decode-uri-component": "0.2.2",
"glob-parent": "6.0.2",
"qs": "6.10.3",
"string_decoder": "1.3.0"
}
tsconfig.json
:
{
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "node",
"target": "es6",
"outDir": "dist",
"rootDir": ".",
"sourceMap": true,
"noImplicitAny": true,
"strict": false,
"resolveJsonModule": true,
"esModuleInterop": true,
"lib": [
"es6"
]
},
"exclude": [
"./gulpfile.ts"
],
"ts-node": {
"esm": true
}
}
node
18.12.1、npm
9.1.3 和 yarn
3.3.0.
这可能是一个迟到的答案,但几个小时后我可以修复它。
gulpfile.ts
gulpfile.cjs
。 gulp-cli
实际上应该首先使用 cjs
文件,但由于某种原因没有使用(查看此问题)package.json
添加一个脚本,告诉 gulp-cli
实际上使用 gulpfile.cjs
而不是 gulpfile.ts
:{
...
"scripts": {
...
"gulp": "gulp -f gulpfile.cjs"
}
}
ts-node
:https://www.npmjs.com/package/ts-node#installationgulpfile.cjs
// Workaround to load the gulpfile as a TypeScript file
require('ts-node').register({
compilerOptions: {
module: 'CommonJS',
},
});
import('./gulpfile.ts');
现在应该可以了。我讨厌 JavaScript。