typescript 错误:无法找到模块“Cannot find”

hpcdzsge  于 2023-05-08  发布在  TypeScript
关注(0)|答案(1)|浏览(650)

当我使用ttsc命令编译typescript项目时,显示错误:

> yarn tscbuild
yarn run v1.22.17
$ ttsc

/Users/John/source/reddwarf/frontend/js-wheel/node_modules/resolve/lib/sync.js:111
    var err = new Error("Cannot find module '" + x + "' from '" + parent + "'");
              ^
Error: Cannot find module 'transformer-module' from '/Users/John/source/reddwarf/frontend/js-wheel'
    at Function.resolveSync [as sync] (/Users/John/source/reddwarf/frontend/js-wheel/node_modules/resolve/lib/sync.js:111:15)
    at PluginCreator.resolveFactory (/Users/John/source/reddwarf/frontend/js-wheel/node_modules/ttypescript/lib/PluginCreator.js:158:34)
    at PluginCreator.createTransformers (/Users/John/source/reddwarf/frontend/js-wheel/node_modules/ttypescript/lib/PluginCreator.js:120:32)
    at Object.newEmit [as emit] (/Users/John/source/reddwarf/frontend/js-wheel/node_modules/ttypescript/lib/patchCreateProgram.js:76:52)
    at emitFilesAndReportErrors (/Users/John/source/reddwarf/frontend/js-wheel/node_modules/typescript/lib/typescript.js:126134:23)

我错过什么了吗?我没有找到名为transformer-module的软件包。我已经按照https://www.npmjs.com/package/ttypescript的说明安装了ttypescript。我该怎么做才能解决这个问题?transformer-module是ttypescript的插件。它应该由ttypescript安装。

67up9zun

67up9zun1#

参考ttypescript提供的示例,以及您问题中的一些信息。
我想你误解了模块的工作原理。
tsconfig.json文件中plugins对象的transform键必须是文件的相对或绝对路径。您可能会保留其文档中指定的值transform-module
例如:

{
    "compilerOptions": {
        "target": "es5",
        "declaration": true,
        "module": "commonjs",
        "strict": true,
        "outDir": "dist",
        "plugins": [
            {
                "transform": "./src/transformers/transformer.ts" /* this line here */
            }
        ]
    },
    "include": ["src/**/*", "node_modules/ttypescript/**/*"],
    "exclude": ["src/transformers/**/*"]
}

来源:他们的例子(https://github.com/cevek/ttypescript/blob/master/packages/ttypescript-examples/tsconfig.json
否则,请随意给予更多的上下文,例如最小的可重复示例

相关问题