kentcdodds / onewheel-blog

109 stars 26 forks source link

fix: Package subpath './lib' is not defined by 'exports' in 'onewheel… #6

Closed Ngorror closed 2 years ago

Ngorror commented 2 years ago

Explanation of the problem (or at least my understanding of it)

In package.json file, devDependencies package msw version ^0.39.2 is used It will install at least msw version 0.45.0 on your computer and then you will receive as sub dependency newer headers-polyfill version 3.1.0 instead of 3.0.4 here is the diff that causes the problem: https://github.com/mswjs/headers-polyfill/compare/v3.0.4...v3.1.0#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519R8 a new declaration of exports will break your npm installation

  "exports": {
    ".": {
      "types": "./lib/index.d.ts",
      "require": "./lib/index.js",
      "default": "./lib/esm/index.js"
    }
  }

Solution

just delete package-lock.json and update manually msw to version 0.47.3 and reinstall all other packages

rm -f -R node_modules
rm -f package-lock.json
npm install msw@0.47.3
npm install 

and voila! npm run dev is working :) you will have the right headers-polyfill version via the updated msw package and new and well tree-shaked package-lock.json

It's my very first "Pull request" in GitLab so probably I wrote the description it the wrong way.

PS. - related to the reported problem When executing "npm run dev" there will be an error message. #5 that I stepped on the same landmine yesterday and managed to "solve" it today