- 1 year ago
How to resolve "Error: Cannot find module 'fsevents'" when using Vite on Windows?
Comment
1 / 1
If you are getting the "Error: Cannot find module 'fsevents'" error when using Vite on Windows, it may be caused by a compatibility issue with the fsevents module.
To resolve this issue, you can try the following steps:
Open a Command Prompt or PowerShell window and navigate to your project directory.
Install the
fsevents
module by running the following command:
npm install fsevents
- Install the
@rollup/plugin-commonjs
module by running the following command:
bashnpm install @rollup/plugin-commonjs
- Install the
rollup-plugin-node-polyfills
module by running the following command:
sqlnpm install rollup-plugin-node-polyfills
- Install the
vite-plugin-node
module by running the following command:
npm install vite-plugin-node
- Open your
vite.config.js
file and add the following code:
javascriptimport commonjs from '@rollup/plugin-commonjs';
import nodePolyfills from 'rollup-plugin-node-polyfills';
import node from 'vite-plugin-node';
export default {
plugins: [
commonjs(),
nodePolyfills(),
node()
]
};
- Save the
vite.config.js
file and restart Vite.
These steps should resolve the "Error: Cannot find module 'fsevents'" issue when using Vite on Windows. Note that the fsevents
module is a Mac-specific module and is not needed on Windows, but it may be required by some dependencies or plugins.