how to specify typescript version to ts-loader?
Asked Answered
S

2

7

I'm installing ts-loader to work with webpack.

Does someone know how to choose which typescript version to use ?

No matter what I do, I always get a message saying

ts-loader: Using [email protected] and /app/tsconfig.json

I intend to use typescript@2 but I have no clue how to tell ts-loader to use the proper version...

Thanks

Swingeing answered 25/11, 2016 at 14:12 Comment(1)
Add typescript@2 to your devDependencies. ts-loader should it use without any configuration. If you don't, it'll use globally installed typescript.Nephridium
E
1

Unfortunately your answer is not sufficient for those who use react-scripts-ts or any other dependencies which require the older version of the typescript. I have added to my package dependency typescript ^2.6.2, but ts-loader still shows typescript 2.5.3, because "react-scripts-ts" has a dependency "typescript":"~2.5.3", so somehow that dependency takes precedence.

The actual solution that I found is creating npm-shrinkwrap.json file where I override subdependency of react-scripts-ts to the correct dependency, something like this:

{
    "dependencies":
    {
        "react-scripts-ts":
        {
            "dependencies":{
                "typescript": { "version": "2.6.2" }
            }
        }
    }
}

After creating this file, I remove folder node_modules and execute npm install

If you're not sure which package in your dependency tree depends on specific version of some package, you can find it in package-lock.json file

Enciso answered 27/12, 2017 at 4:19 Comment(0)
S
0

Ok, found it

It turns out typescript was installed by npm as a dependency. And by default it's 1.8

Adding typescript@2 to package.json properly set the typescript version

Swingeing answered 25/11, 2016 at 14:16 Comment(1)
didn't work for me, I have specified 2.6.2 in my package.json, but ts-loader still shows 2.5.2 :-(Enciso

© 2022 - 2024 — McMap. All rights reserved.