question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can include all depencies in the final index.js ?

See original GitHub issue

Hi,

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:open
  • Created a year ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
egoistcommented, May 26, 2022

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.

3reactions
tomglenncommented, May 26, 2022

@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:

Packages required by your application in production.

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:

Packages that are only needed for local development and testing.

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 for tsup 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 the noExternal flag anywhere on that page, for that you have to go to the API docs and even then the description for noExternal 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NodeJS - How to inject all dependencies in existing project?
In the end, the code you pasted in your question will work without having to open and serve the index.html file inside http....
Read more >
A Guide to Managing Webpack Dependencies - Toptal
A Guide to Managing Webpack Dependencies. The Webpack module bundler processes JavaScript code and all static assets, such as stylesheets, images, and fonts....
Read more >
Understanding dependencies inside your Package.json
In this blog post, you can find a list and description of dependencies and other host Specs inside package.json . The dependencies in...
Read more >
How to force require.js to load all resources from one directory
I have typescript generating a javascript file that starts with this line: define(["require", "exports", "jquery", "chart.js", ".
Read more >
How To Use Node.js Modules with npm and package.json
The node_modules folder contains every installed dependency for your project. In most cases, you should not commit this folder into your version ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found