Сценарий npm только с ts-узлом дает сбой - PullRequest
0 голосов
/ 01 июля 2019

У меня, казалось бы, простой скрипт npm, который не работает, но я не могу понять, почему.У меня установлены следующие пакеты глобально:

+-- ts-node@8.3.0
+-- tsconfig-paths@3.8.0
+-- typeorm-model-generator@0.3.4
`-- typescript@3.5.2

Когда я запускаю ts-node из командной строки, он запускается, как и ожидалось.

В моем package.json файле, который у меня есть:

"scripts": {
    "ts_test": "ts-node"
},

Когда я запускаю npm run ts_test, я получаю следующую ошибку:

SyntaxError: Unexpected token } in JSON at position 581
    at JSON.parse (<anonymous>)
    at parse (...\node_modules\tsconfig\src\tsconfig.ts:195:15)
    at readFileSync (...\node_modules\tsconfig\src\tsconfig.ts:181:10)
    at Object.loadSync (...\node_modules\tsconfig\src\tsconfig.ts:151:18)
    at readConfig (...\node_modules\ts-node\src\index.ts:425:18)
    at Object.register (...\node_modules\ts-node\src\index.ts:189:18)
    at Object.<anonymous> (...\node_modules\ts-node\src\_bin.ts:140:17)
    at Module._compile (internal/modules/cjs/loader.js:721:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Module.load (internal/modules/cjs/loader.js:620:32)

Любые советы о том, что можетвызвать эту ошибку или как дальнейшую отладку было бы полезно.

Обновление: ниже мой файл tsconfig:

{
  "compilerOptions": {
    "lib": [
      "es2017"
    ],    
    "baseUrl": "/",
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "strictNullChecks": true,
    "strictPropertyInitialization": false,
    "moduleResolution": "node",
    "sourceMap": true,
    "target": "es2017",
    "outDir": "lib",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
    "esModuleInterop": true,
  },
  "exclude": [
    "node_modules"
  ]
}

1 Ответ

1 голос
/ 01 июля 2019

Спецификация JSON не поддерживает конечные запятые. Из-за этого разбирается ваша tsconfig.json. Измените tsconfig.json на

{
  "compilerOptions": {
    "lib": [
      "es2017"
    ],    
    "baseUrl": "/",
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "strictNullChecks": true,
    "strictPropertyInitialization": false,
    "moduleResolution": "node",
    "sourceMap": true,
    "target": "es2017",
    "outDir": "lib",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "esModuleInterop": true
  },
  "exclude": [
    "node_modules"
  ]
}
...