Compile typecript files from a script in package.json

0

I'm doing a project in typescript and I want to execute the command that I usually use to compile the .ts files from a script in the file package.json and so I could run the script as:

npm run nombrescript

This is the tsconfig.json:

{
    "compilerOptions": {
        "lib": [ "es2015" ],
        "module": "commonjs",
        "moduleResolution": "node",
        "target": "es5",
        "noImplicitAny": true,
        "sourceMap": false,
        "outDir": "src"
    },
    "include": [
        "**/*", "."
    ],
    "exclude": [
        "node_modules"
    ]
}

and that's how I define the scripts:

  "scripts": {
    "build": "ntsc",
    "build:watch": "ntsc --watch"
  }

The problem I'm having

Running ntsc or ntsc --watch from the console compiles the files in the destination.

When I run it as npm run build or npm run build:watch I get the following error:

  

TypeError: Path must be a string. Received undefined

If I now change the script as follows:

"build": "ntsc ."

I receive the following error:

  

Error: references.d.ts not found in. or any of its parents

Why does not the same command work if I include it in scripts in the package.json?

My ultimate goal is to be able to execute that script in the postinstall. How can I solve to execute it as npm run build ?

    
asked by Jose Hermosilla Rodrigo 07.05.2017 в 23:27
source

1 answer

0

Apparently the error was because I did not have ntypescript installed as dependency.

According to the documentación , this fixes the problem:

npm install ntypescript@latest --save --save-exact
    
answered by 07.05.2017 в 23:34