公司的仓库又深又乱,我索性重新起了一个git仓库,把公司的目录git submodule add ** public加进来。只运行我工作的模块。其中运行gulp的时候遇到了问题,原本的gulpfile.ts现在是 public\gulpfile.ts, 当我执行gulp dev --gulpfile public\gulpfile.ts的时候,给我干出两个错误。
先是报了
SyntaxError: Cannot use import statement outside a module
于是按网上的办法,添加"type": "module"到public\package.json(试过了根目录的package.json没用),结果换了一个新的问题
Unknown file extension ".ts"
搜了半天没发现解法。最后是根目录上面的有个tsconfig.json,
// tsconfig.json
"include": [ "./src" ],
"compilerOptions": {
"module": "ES2020",
}
虽然 incudle里面不包含public目录,但是他还是影响了子目录的gulp运行。
处理办法是
// tsconfig.json
"compilerOptions": {
"module": "commonjs", // 改成这个或者删掉
}
结合上面一个问题来看,gulpfile.ts 需要被视为cjs来运行才行。