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.

Provide ability to bundle dev dependencies for Node adapter

See original GitHub issue

Describe the problem

Currently, the Node adapter will not bundle any external server side dependencies. This means that you need to make all of the dependencies you might need at runtime be prod dependencies. This differs from its (recent) previous behavior, and from Sapper’s behavior, and from (I would argue) expected behavior.

Until now, it’s been standard operating procedure to bundle as many of the server-side dependencies as possible, to reduce the deployed app size, parse time, and startup time. If there’s some good reason to stop doing this, it should certainly at least be documented.

This issue may also well apply to other adapters (other than the static one), but I haven’t tried to validate that.

Describe the proposed solution

I’m not entirely sure. It would be nice to be able to provide sensible default Vite configuration so that we have Vite do it, rather than do this in a separate esbuild step afterwards (either automatically or manually).

I don’t know whether some different behavior from Vite would make this easier on our end, or whether this is something that Vite ought to change.

Below, I describe what I’m currently doing in userland to deal with this, but I’m not positive that this would have an equivalent in-framework analogue. (Do we have convenient access to the user’s project’s package.json?)

Alternatives considered

Currently, I have a vite.ssr.noExternal setting of process.env.NODE_ENV === "development" ? undefined : Object.keys(pkg.devDependencies) (where pkg is the parsed JSON from package.json) to force Vite to bundle all of my dev dependencies.

The check for development vs prod mode is there because I was having an issue using Object.keys(pkg.devDependencies) in dev mode that I haven’t fully tracked down or tried to reproduce in a minimal repo, but which seem to stem from having a CJS-only dependency that Vite doesn’t try to convert to ESM during dev mode.

Importance

would make my life easier

Additional Information

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:8
  • Comments:21 (9 by maintainers)

github_iconTop GitHub Comments

5reactions
Conduitrycommented, Aug 29, 2022

This should be good to go now in 1.0.0-next.88 of the Node adapter. When you update, you should remove any workarounds you added for this issue, including my ssr Vite config and including adding SvelteKit’s runtime dependencies as direct prod dependencies of your app.

3reactions
moisesbitescommented, Aug 20, 2022

Edit: As others pointed out, adding devalue, cookie and set-cookie-parser as production dependencies and running npm ci --prod fixes the issues, including the import { json } from '@sveltejs/kit' error I mentioned above.

I think the process of build need to add adapter node dependencies in production. It’ very confusing if every time this dependencies was changed, we would need to start the app in production to discover that some packages is not there.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adding dependencies to a package.json file - npm Docs
Specifying dependencies and devDependencies in a package.json file ... run npm install , npm will download dependencies and devDependencies that are listed ...
Read more >
eslint should be listed in the project's dependencies, not ...
Solved it with adding this to my .eslintrc : "import/no-extraneous-dependencies": ["error", {"devDependencies": true}].
Read more >
Bundling and Building with Parcel - Beginner JavaScript
Your server will know exactly what JavaScript files to deliver to you. ... That will add Parcel as a dev dependency in our...
Read more >
Specifying dependencies in Node.js - Cloud Functions
When this script is executed, the dependencies in the dependencies and devDependencies fields of your package.json file are available. After executing your ...
Read more >
Client Side Development with Spring Boot Applications
Install Node.js; Adding NPM Packages; Building with Rollup ... Many of the samples use Webjars to deliver the Javascript (and CSS) assets to ......
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