How can include all depencies in the final index.js ?
See original GitHub issueHi,
I think that my question is about a basic usage but I can’t find instruction in documentation or other issues and discussions…
So, I want to build a single index.js wich inclue all other typescript files (it’s already good for that) and all depencies, on a typescript project.
Actually, if i do a tsup src/index.ts
at root, a dist folder is built with the famous index.js inside.
But, this index.js work only in this dist folder (or at root of project).
So, if I put this file on my production server (without any package.json or node_modules folder), and I do a node index.js
, some error are printed to say that modules aren’t found (package.json depencies).
Could you help me to find the correct arguments to include all depencies at build time 🙏.
Thanks by advance.
Issue Analytics
- State:
- Created a year ago
- Comments:9 (1 by maintainers)
Top GitHub Comments
think of it like this:
tsup bundles everything you imported by default, just like parcel or webpack, but “dependencies” and “peerDependencies” are externalized because they are available at runtime, since you usually use tsup to publish a library, whose “dependencies” will be downloaded when user installs your library.
@OmgImAlexis @egoist Thank you both for taking the time to explain. While on the surface what you’re saying makes logical sense (the packages do not need to be imported at runtime because they’re already bundled in the final JS), it does not make semantic sense as per the NPM documentation (https://docs.npmjs.com/specifying-dependencies-and-devdependencies-in-a-package-json-file) whereby the description of
dependencies
is:If I’m importing the
uuid
package into my application, semantically it is required by my application in production. Whether it’s bundled into the final JS or not.The definition for
devDependencies
is:I’m aware there are arguments for various approaches here (i.e. https://jsramblings.com/do-dependencies-devdependencies-matter-when-using-webpack/). But semantically, having all dependencies as devDependencies is confusing and not the JS standard way of developing. It also goes against the grain when it comes to the way other bundlers work, so it may just be worth making this a little clearer in the documentation and even explaining why
tsup
takes this approach.Just as a side, I’m using this in a slightly different context to what I suspect most people are, in that I’m producing a JS bundle that is being used inside Goja (a Go implementation of ES5 - https://github.com/dop251/goja) so I don’t have access to node modules at runtime. It also means I can’t use Node built in features like
crypto
.Apologies, I’m not trying to be argumentative for the sakes of it. But when swapping out
rollup
fortsup
it had me confused for a good 30 minutes trying to understand why it wasn’t bundling my external packages. So some clearer documentation here would be extremely helpful. It’s briefly mentioned in your docs here https://tsup.egoist.sh/#excluding-packages but there is no mention of thenoExternal
flag anywhere on that page, for that you have to go to the API docs and even then the description fornoExternal
isn’t immediately obvious what it does.With all that said, I’m enjoying the speed of
tsup
very much so thank you for all your hard work.