Typescript компилируется, но не может работать из-за отсутствия разрешения модуля - PullRequest
0 голосов
/ 03 ноября 2019

Я могу скомпилировать свой код, используя tsc, но в тот момент, когда я пытаюсь запустить свой код, я получаю ошибку:

$ node ./outdir/services/preDeployPrepare/main.js
internal/modules/cjs/loader.js:670
    throw err;
    ^

Error: Cannot find module 'enums'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:668:15)
    at Function.Module._load (internal/modules/cjs/loader.js:591:27)
    at Module.require (internal/modules/cjs/loader.js:723:19)
    at require (internal/modules/cjs/helpers.js:14:16)
    at Object.<anonymous> (C:\cos-tools\singularityGroupHQ\outdir\services\preDeployPrepare\main.js:3:17)
    at Module._compile (internal/modules/cjs/loader.js:816:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
    at Module.load (internal/modules/cjs/loader.js:685:32)
    at Function.Module._load (internal/modules/cjs/loader.js:620:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:877:12)
error Command failed with exit code 1.

моя конфигурация ts:

{
    "compilerOptions": {
        "baseUrl": ".",
        "paths": {
            "@enums": ["./src/enums"],
            "@types": ["./src/typings"],
            "@tools": ["./src/tools"],
            "@features": ["./src/features"],
            "@errors": ["./src/errors"],
            "@middleware": ["./src/middleware"],
            "@mocks": ["./src/mocks"],
            "@mongo": ["./src/mongo"],
            "@presets": ["./src/presets"],
            "@routes": ["./src/routes"],
            "@services": ["./src/services"],
            "@api": ["./src/api"],
            "@typeguards": ["./src/typeguards"]
        },
        /* Basic Options */
        "outDir": "outdir",
        "rootDir": ".",
        "target": "ES2018",
        "module": "commonjs",
        "lib": ["esnext"],
        "declaration": true,
        "declarationMap": true,
        "sourceMap": true,
        "composite": true,
        "removeComments": true,
        "noEmit": false,
        "pretty": true,
        "jsx": "react",
        "incremental": true,

        /* Strict Type-Checking Options */
        "strict": true,
        "noImplicitAny": true,
        "strictNullChecks": true,
        "strictFunctionTypes": true,
        "noImplicitThis": true,
        "alwaysStrict": true,
        "strictPropertyInitialization": true,
        "strictBindCallApply": true,

        /* Additional Checks */
        "noUnusedLocals": true,
        "noUnusedParameters": true,
        "noImplicitReturns": true,
        "noFallthroughCasesInSwitch": true,

        /* Module Resolution Options */
        "moduleResolution": "node",
        "typeRoots": ["node_modules/@types"],
        "esModuleInterop": true,
        "resolveJsonModule": true,
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true
    },
    "exclude": ["outdir"]
}

Iпопытался изменить мои пути, базовый URL и корневой URL, но, похоже, ничего не работает. Я полагаю, что так работает отображение, и, хотя оно компилируется, скомпилированный код не получает перечисления?

Поскольку перечисления являются специальными объектами в js, нужно ли включать перечисления в один из параметров конфигурации ts?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...