Last updated: Apr 4, 2024
Reading timeยท4 min
package.json
filenpm install
command with the --force
optionnpm audit fix
npm
package-lock.json
fileThe error "npm ERR! code EBADPLATFORM Unsupported platform for fsevents"
occurs when we try to install the fsevents
module on an unsupported operating
system.
To solve the error, make sure that the package you are trying to install is
supported by your operating system, delete your node_modules
and reinstall
your dependencies.
npm ERR! code EBADPLATFORM npm ERR! notsup Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin"} (current: {"os":"linux","arch":"x64"}) npm ERR! notsup Valid OS: darwin npm ERR! notsup Valid Arch: undefined npm ERR! notsup Actual OS: win32 npm ERR! notsup Actual Arch: x64
The error most commonly occurs with the fsevents and chokidar packages.
The fsevents
module provides native access to macOS File System events in
Node.js.
The module only supports macOS, so trying to install it on Windows or Linux causes the error.
If you install a package that depends on fsevents
while running on Windows or
Linux, it will automatically get skipped with the following warning.
The warning occurs because fsevents
is an optional dependency that is only
installed on macOS computers.
NPM knows to automatically skip the dependency if you aren't on macOS.
package.json
fileOpen your package.json
file (should be located at the root of your project)
and make sure the fsevents
module is not in your dependencies
or
devDependencies
objects.
dependencies
and devDependencies
objects because trying to run npm install
on Windows or Linux would fail.Instead, if you'd like to specify fsevents
as a dependency, use the
optionalDependencies
object.
"optionalDependencies": { "fsevents": "^2.3.2" }
You can optionally change the version if you need to install a specific version
of fsevents
.
optionalDependencies
object is used if you'd like npm to proceed if it cannot find the specified dependency or fails to install it.If the npm install
command is run on macOS, then the installation of
fsevents
will succeed, otherwise, it will simply get skipped.
If you want to skip installing optional dependencies without checking if the
installation is successful, set the --omit
flag to optional
.
npm install --omit=optional
If the error persists, try to delete your node_modules and
package-lock.json (NOT
package.json
) files.
If you are on Windows, issue the following commands from the root directory of
your project (where your package.json
file is).
# Windows rd /s /q "node_modules" del package-lock.json del -f yarn.lock # ๐๏ธ clean npm cache npm cache clean --force npm install
If you are on macOS and Linux, issue the following commands from the root directory of your project.
# macOS and Linux rm -rf node_modules rm -f package-lock.json rm -f yarn.lock # ๐๏ธ clean npm cache npm cache clean --force npm install
Check if the error persists after reinstalling your node modules.
npm install
command with the --force
optionIf the error persists, try to run the npm install
command with the --force
option.
npm install --force
npm audit fix
If the error persists, try to run
npm audit fix with the --force
option.
npm audit fix --force
Check your terminal for messages with additional information.
npm
Another thing you can try is to update your version of npm
.
npm install -g npm@latest
If you use an older npm
version, it might be the cause of the issue.
If you get a permissions error on macOS or Linux, prefix the command with
sudo
.
# ๐๏ธ If you get a permissions error on macOS / Linux sudo npm install -g npm@latest
If you get a permissions error on Windows, open CMD as an admin.
Click on the Search bar and type CMD.
Right-click on the Command Prompt application and click "Run as administrator".
npm install -g npm@latest
package-lock.json
fileIf the error persists, open your package-lock.json
file.
It is located in the root directory of your project, right next to your
package.json
file.
Press Ctrl
+ F
and search for "node_modules/fsevents"
.
Add the wind32
and linux
operating systems to the os
array.
"node_modules/fsevents": { // ... rest "os": [ "darwin", "win32", "linux" ], // ... rest }
After adding the operating systems to the os
array, try running the
npm install
command.
npm install
Note: if the issue persists and the message is just a warning (and not an error), you can safely ignore it.
Usually, NPM knows to not try to install OS-specific packages on not-supported operating systems.