-
-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
Build artifacts depend node_modules, [email protected] #5190
Comments
This is common across all Typescript projects that use tsc (which nest does my default) instead of using a bundling tool (like webpack which nest is also compatible with). Even node projects by default depend on |
I tried with webpack but I get the same result (change build in --webpack). Meaning, the content of dist is different, but the error is the same. In #1706 the problem seemed that they had to ignore some modules to make sure webpack could complete. Here webpack works, but then same exact |
Right, Nest's webpack configuration uses webpack-node-externals, which means that everything your applications uses You're always welcome to build your own webpack configuration that would bring everything into a single file, but Nest will not provide the config for that. |
Oh ok, thank you for the insights. Closing this then. |
I didn't solve, I'm not packing into 1 single js file. Sorry... |
Some contradictions arises, however. If nestjs was heavily designed with an "Angular" perspective, then this way of building is completely different. You may build an angular application (Typescript) and get a To me, it should be an improvement for nestjs. Because as Angular, nestjs is heavily opinionated also. So having a bundler and produce an independent build will provide an extraordinary way of delivering nest applications. Adding to that, containers will get the benefits of simplifying and minimizing the deployment. Today, you need to install dependencis, prune them for production, and moving node_modules around together with your dist. That's not a build, from my perspective. It's just a dev environment being served. |
@gentunian the reason Angular can create this production build option is because of how the browser environment works. There's no dependencies on C++ bindings or python libraries, there's no worries about database connections, there's just JavaScript, HTML, and CSS. With Node, you have these C++ bindings in packages like Heroku already manages this install, build, prune step for you. AWS is completely hands off and has multiple paths you could take (ECS, ECR, lambda, etc). Docker is another hands off approach and I have a sample tempalte here if you'd like to take a look using a multi-step build. Nest's architecture is heavily inspired by Angular, that is and always will be true. But due to differences between the browser and node environment, providing the "right" build script to cover all cases (even all basic cases) would be difficult in its own right. IF we were to attempt this (and that's a bit if) what do you say the build should do? Right now, |
@jmcdo29 good point. For one project I needed to make use of (edit to avoid getting people notified) FROM node:12-alpine as deps
WORKDIR /app
COPY package*.json .
RUN npm ci
FROM node:12-alpine as build
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npm run build && npm prune --production
FROM node:12-alpine
WORKDIR /app
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/dist ./dist
EXPOSE 3000
CMD [ "node", "dist/main" ] |
It might be interesting. It looks like pkg works on the compiled JS, so it could be a secondary step taken. It looks like |
Might be necroposting, but you can do this with ncc by vercel: ncc build ./dist/main.js -m -C -o ./ncc
node ./ncc/index.js example: I got an error with |
Our experience with this: Works like a charm unless you are using typeorm migration scripts. ncc does not compile these and thus typeorm is not able to find them at runtime. This is a known problem of ncc: vercel/ncc#578 |
Bug Report
Build artifacts depend
node_modules
.This is analogous to #1706, but for Nestjs 7.
The issue seems different as it's not a building issue, but an issue after building succeeds. I tried to follow the discussion in #1706 but I couldn't find a fix. Can anyone provide a resolution?
Current behavior
Repro:
Expected behavior
After build, the artifacts in
dist
should run without depending onnode_modules
.Environment
(I'm on node12/macosx, but the same happens if I build within Docker)
The text was updated successfully, but these errors were encountered: