TS-узел не обрабатывает импорт в файлах node_modules - PullRequest
0 голосов
/ 21 апреля 2020

У меня есть проект (api-service), написанный на машинописном тексте, который запускается с использованием ts-node. Я также написал пакет под названием dataservices, который я только что импортировал в api-service, используя наш собственный внутренний репозиторий. Некоторые из файлов dataservices импортируются из других Javascript файлов, например, используя Luxon. Ранее я использовал dataservices в проекте веб-пакета раньше, без проблем.

Но когда я пытаюсь запустить api-service и использовать импорт из dataservices, он жалуется, что есть синтаксическая ошибка, которую я считаю вызванный тем, что ts-node не выполняет импорт в dataservices:

yarn run v1.12.3
$ nodemon
[nodemon] 1.19.4
[nodemon] to restart at any time, enter `rs`
[nodemon] watching dir(s): src/**/*
[nodemon] watching extensions: ts
[nodemon] starting `ts-node ./src/index.ts`
Loading configuration...
Verifying configuration...
Building Server...
/server/node_modules/@my_company/dataservices/lib/metricsService.js:1
(function (exports, require, module, __filename, __dirname) { import { formatDate, parseDate } from "./Helpers";
                                                                     ^
SyntaxError: Unexpected token {
    at new Script (vm.js:79:7)
    at createScript (vm.js:251:10)
    at Object.runInThisContext (vm.js:303:10)
    // ...

Я не уверен, какая комбинация параметров компилятора и конфигурации мне нужна, чтобы позволить ему следовать импортам в модуле, импортированном из node_modules. Мне нужен вавилон?

tsconfig для моей dataservices посылки:

{
  "compilerOptions": {
    /* Basic Options */
    "target": "ESNEXT",                       /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
    "module": "commonjs",                       /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
    "allowJs": false,                         /* Allow javascript files to be compiled. */
    "declaration": true,                   /* Generates corresponding '.d.ts' file. */
    "outDir": "./lib",                       /* Redirect output structure to the directory. */

    /* Strict Type-Checking Options */
    "strict": true,                           /* Enable all strict type-checking options. */
    "noImplicitAny": true,                    /* Raise error on expressions and declarations with an implied 'any' type. */
    "strictNullChecks": true,                 /* Enable strict null checks. */
    "strictFunctionTypes": true,              /* Enable strict checking of function types. */
    "strictPropertyInitialization": true,     /* Enable strict checking of property initialization in classes. */
    "alwaysStrict": true,                     /* Parse in strict mode and emit "use strict" for each source file. */

    /* Module Resolution Options */
    "moduleResolution": "node",               /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
    "esModuleInterop": true,                  /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */

    /* Experimental Options */
    "experimentalDecorators": true,           /* Enables experimental support for ES7 decorators. */
    "emitDecoratorMetadata": true            /* Enables experimental support for emitting type metadata for decorators. */
  },
  "include": [
    "src"
  ],
  "exclude": [
    "node_modules",
    "lib"
  ]
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...