How to fix “Error: No valid exports main found for ‘/node_modules/packname by Godwill Barasa

On 12th May, as I was trying to “npm run dev” a react application that I hadn’t pulled from the master branch in a while, I came across the following error when trying to start the app:

Error: No valid exports main found for ‘/node_modules/postcss’

Quick google search, I noticed the problem is because of one or more of the packages was bumped to support a more recent version. So, I checked what is the version I was running:

node -v

Turns out I was running V.10, yet the package was updated for version 13.

Next thing was to install nvm. This piece of software allows you to install and maintain many different independent versions of Node.js, and their associated Node packages, at the same time. visit the project’s GitHub page.

Before piping the command through to bash, it is always a good idea to audit the script to make sure it isn’t doing anything you don’t think might be indifferent from your case

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh

Take a look and make sure you are comfortable with the changes it is making. When you are satisfied, run the command again with | bash appended at the end.

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

This will install the nvm script to your user account. To use it, you must first source your .bashrc file:

source ~/.bashrc

Now, you can ask NVM which versions of Node are available:

nvm list-remote

This will list a whole bunch of versions, just select a newer version. In my case I contacted the software developer asked him which version he was using in his dev environment. Turns out he uses v14.5

It’s a very long list! You can install a version of Node by typing any of the release versions you see.

nvm install v14.5

You can see the different versions you have installed by typing:

nvm list

You can switch between installed versions with nvm use:

nvm use v13.6.0

Now using node v13.6.0 (npm v6.13.4)

You can verify that the install was successful using the same technique from the other sections, by typing:

node -v

Output

v13.6.0

Then I,

npm cache clean — force

Delete node_modules by

rm -rf node_modules

delete the package-lock.json file too.

To install the dependencies again.

npm install

Last step was to run, npm run dev which worked perfectly

--

--

--

Award-winning Software Developer, Writer and Designer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Summary for angular-observable-pipe

5 JavaScript Frameworks That You Must Try In 2021

The isNaN() Function For JavaScript

A pair of Owl butterflies imitating the face of an owl.

How to type react-redux style HOC in Typescript

Functional compostion and lodash

npm ERR! code Z_BUF_ERROR

React-navigation with redux and immutable.js

Blog Post 204

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Godwill Barasa

Godwill Barasa

Award-winning Software Developer, Writer and Designer

More from Medium

How to use Redux-Toolkit. A Step-by-Step Guide.

Choices: A React-Redux Horror Game (Part 2)

JavaScript Example- Rendering Some Data to the DOM with fetch()

Building Cult.fit Clone in 6 Days