reactjswebpacksnowpack

Snowpack is not reloading


i started to use snowpack and ran into a big problem. Snowpack is not hot reloading for me. I tried the basic minimal template, a svelte template and a react template - Everytime the same problem. I also created on from scratch based on the getting started.

Here a my example files:

index.jsx

import React from 'https://cdn.skypack.dev/react';
import ReactDom from 'https://cdn.skypack.dev/react-dom';

ReactDom.render(
  <React.StrictMode>
    <div>This is working</div>
  </React.StrictMode>,
  document.getElementById('root'),
);

// Hot Module Replacement (HMR) - Remove this snippet to remove HMR.
// Learn more: https://www.snowpack.dev/concepts/hot-module-replacement
if (import.meta.hot) {
  import.meta.hot.accept();
}

snowpack.config.js

/** @type {import("snowpack").SnowpackUserConfig } */
module.exports = {
  mount: {
    public: { url: '/', static: true },
    src: { url: '/dist' },
  },
  plugins: ['@snowpack/plugin-react-refresh'],
  packageOptions: {
    /* ... */
  },
  devOptions: {
    /* ... */
  },
  buildOptions: {
    /* ... */
  },
};

package.json

{
  "name": "chatclient",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "start": "snowpack dev",
    "build": "snowpack build",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@snowpack/plugin-react-refresh": "^2.4.0",
    "snowpack": "^3.0.11"
  }
}

I hope someone can help me. Snowpack is such an amazing tool but i can't get it to work.


Solution

  • I found a solution

    Credits

    I used to run my dev environment on wsl2. Some no known reason does nodejs not hot reload when you are in wsl2 and the files are on the windows filesystem. Moved everything to my linux filesystem and i worked.

    I hope someone will find this helpful!