Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Snowpack dev server is not recompiling files in node_modules when changed

I have a snowpack project that I started from the blank template. My index.js file calls a function from another module I'm developing that I have installed using npm link.

When I change a file in the other module, it doesn't get updated in snowpack. Even when I restart the dev server, it doesn't update. I have to restart snowpack with the --reload argument to clear the cache.

How do I make sure changes to files in node_modules get recognized by snowpack so that they are rebuilt?

like image 739
Ben Davis Avatar asked Nov 20 '20 02:11

Ben Davis


People also ask

What is snowpack Dev Server?

snowpack dev - Snowpack's dev server is an instant dev environment for unbundled development. The dev server will build a file only when it's requested by the browser. That means that Snowpack can start up instantly (usually in <50ms) and scale to infinitely large projects without slowing down.

How to monitor changes in node_modules in Webpack?

You can config in in webpack.config file or in WebpackDevServer option, to watch for changes also in node_modules (i think that by default webpack watching for changes in all files) in the following example webpack ignored all changes in node_modules folder except specific module.

What is snowpack?

Snowpack's unbundled web development server starts up in 50ms or less and stays fast in large projects. Snowpack never builds the same file twice. Powered by JavaScript’s native module system (ESM) in the browser.

How do I fix snowpack build error?

Snowpack build error If you bootstrap your project snowpack using there create react app template i.e like 1npx create-snowpack-app new-dir --template [SELECT FROM BELOW] [--use-yarn] Chances are higher that you might see this error very age of development. Easy and not time taking is simply repace your .js extension to .jsx that's it.


2 Answers

Unfortunately the way Snowpack works is it caches the node_modules dependencies and rarely rebuilds them.

In the documentation section Using NPM Dependencies

  1. Because your dependencies rarely change, Snowpack rarely needs to rebuild them.

Each build tool has its pros and cons, and Snowpack is not going to work for you, in this instance where you still need to update the linked dependency.

You might want to look at other build tools like Webpack. Here is stack overflow answer on correctly configure Webpack to watch only for the linked dependency.

It seems that even the Parcel 2 doesn't detect changes in linked dependencies.

like image 114
Quintin Henn Avatar answered Oct 28 '22 12:10

Quintin Henn


You can delete .cache/snowpack inside node_modules folder for rebuilding. More concise you can delete specific folder which you want to make it rebuild, This is only hack I found that works.

like image 25
Shubham Verma Avatar answered Oct 28 '22 11:10

Shubham Verma