Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installing as a dev dependency will crash the app after installing as production-only #150

Open
nolawnchairs opened this issue Jun 16, 2023 · 5 comments

Comments

@nolawnchairs
Copy link

It's not a bug per se, but it should be mentioned in the Readme that any application running with this library installed as a dev dependency and built with either npm install -only=production or npm ci -only=production will not bundle this package, and when referenced in code will cause the application to crash.

You can test with the following Dockerfile:

FROM node:18.16.0-alpine3.18

RUN mkdir -p /app && chown -R node:node /app

USER node

WORKDIR /app

COPY --chown=node:node package*.json ./

RUN npm ci --only=production

COPY . .

CMD [ "node", "dist/index.js" ]

Assuming that the src directory has a single index.ts that when built will output JS to the dist directory.

import '@total-typescript/ts-reset'

const a = [1, 2, 3, 4, 5, 6, 7, 8, undefined, 10]
const b = a.filter(Boolean)

console.log(b)
@MDReal32
Copy link

ts-reset not for dev dependency. It's directly changes types (yes in dev) but have a js files too. that means import going for js files too. in that case u importing node_modules/@total-typescript/ts-reset/dist/recommends.js

@ArthurKa
Copy link

ts-reset not for dev dependency

Why? Just use it correctly not as import in file but in tsconfig.json:

"compilerOptions": {
  "types": [
    "@types/node",
    "@total-typescript/ts-reset",
  ],
}

@GollyJer
Copy link

This seems like the way.
Why is creating a reset.d.ts the recommended approach?

@ArthurKa
Copy link

I dunno 🤷‍♂️. Probably @mattpocock knows.

@moltar
Copy link

moltar commented Oct 6, 2023

This will not always work:

"compilerOptions": {
  "types": [
    "@types/node",
    "@total-typescript/ts-reset",
  ],
}

Here's a concrete example, and a pretty typical use case:

    "typeRoots": [
      "./node_modules/@types"
    ],
    "types": [
      "node"
    ],

Adding @total-typescript/ts-reset to the setup above will instruct TS to search in ./node_modules/@types/@total-typescript/ts-reset

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants