Skip to content

Package missing error from Typescript 7 via npmΒ #63668

Description

@mind-bending-forks

πŸ”Ž Search Terms

"Unable to resolve" "Either your platform is unsupported, or you are missing the package on disk."

πŸ•— Version & Regression Information

  • This changed between versions 6.0.3 and 7.0.2

⏯ Playground Link

No response

πŸ’» Code

npm package.json specifies typescript ^7.0.2:

{
  ...,
  "devDependencies": {
    ...
    "typescript": "^7.0.2",
    ...
  }
  
}

npm package-lock.json generated via:

npm install --package-lock-only

Then, dependencies installed via

npm ci --omit=optional --ignore-scripts

Finally, typescript executed via a command like:

npm exec --no --offline --package typescript -- 'tsc' --target ES2016 --module ES2015 --moduleResolution bundler --allowSyntheticDefaultImports true --strict --outDir /some/directory /some/typescript/file.ts

(A much simpler command would have the same effect!)

πŸ™ Actual behavior

Typescript command fails with the following error:

file:///some/directory/node_modules/typescript/lib/getExePath.js:53
            throw new Error("Unable to resolve " + platformPackageName + ". Either your platform is unsupported, or you are missing the package on disk.");
                  ^

Error: Unable to resolve @typescript/typescript-linux-x64. Either your platform is unsupported, or you are missing the package on disk.
    at getExePath (file:///some/directory/node_modules/typescript/lib/getExePath.js:53:19)
    at file:///some/directory/node_modules/typescript/lib/tsc.js:6:13
    at ModuleJob.run (node:internal/modules/esm/module_job:439:25)
    at async node:internal/modules/esm/loader:643:26
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:101:5)

πŸ™‚ Expected behavior

Typescript command completes without error, as it does if the process is repeated with version ^6.0.3 in package.json.

Additional information about the issue

I'm not sure whether this is an actual bug, or just a change in the way typescript handles dependencies between version 6 and 7, whereby it did not rely on optional dependencies at version 6, but does rely on platform-specific optional dependencies at version 7. My understanding of optional dependencies is that they are for dependencies that are not necessary for the application to run, so was surprised by this. However, having researched a bit further, it appears that npm may lack support for platform-specific dependencies, and so the issue may be with npm. However, we do not wish to blanket allow optional dependencies in npm just for typescript to work, so our workaround for the moment will be to add @typescript/typescript-linux-x64 as an explicit dependency in our package.json, since our application will only be run on Linux. That workaround may not work for other people though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ExternalRelates to another program, environment, or user action which we cannot control.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions