Installing as a dev dependency will crash the app after installing as production-only
Opened this issue ยท 5 comments
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)
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
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",
],
}
This seems like the way.
Why is creating a reset.d.ts
the recommended approach?
I dunno ๐คทโโ๏ธ. Probably @mattpocock knows.
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