iamshaunjp / Complete-React-Tutorial

All course files for the Complete React Tutorial on the Net Ninja YouTube channel.
1.81k stars 1.72k forks source link

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/tokenize' is not defined by "exports" #16

Closed tpmccallum closed 2 years ago

tpmccallum commented 2 years ago

Part 1

Hi I am trying to build the latest lesson in this set (lesson-32).

I get the following error

$ npm run build

> dojo-blog@0.1.0 build
> react-scripts build

node:internal/modules/cjs/loader:488
      throw e;
      ^

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/tokenize' is not defined by "exports" in /home/tpmccallum/SSR/blog/Complete-React-Tutorial/dojo-blog/node_modules/postcss-safe-parser/node_modules/postcss/package.json
    at new NodeError (node:internal/errors:372:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:440:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:719:3)
    at resolveExports (node:internal/modules/cjs/loader:482:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/home/tpmccallum/SSR/blog/Complete-React-Tutorial/dojo-blog/node_modules/postcss-safe-parser/lib/safe-parser.js:1:17) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

Part 2

I would like to get this blog working as a server-side rendered app as per the following tutorial (which takes a create-react-app style app and delegates the JavaScript UI rendering to a server). The reason I chose this repository is because it follows the create-react-app closely in terms of convention and layout etc. and therefore is possibly the best app to test converting a React app to SSR

https://wasmedge.org/book/en/dev/js/ssr.html

tpmccallum commented 2 years ago

I managed to resolve this error by tidying up my Ubuntu environment.

npm install --save react react-dom react-scripts
npm install -g npm@latest
rm -rf node_modules/
npm install
npm run build

The build is now successful

> dojo-blog@0.1.0 build
> react-scripts build

Creating an optimized production build...
Compiled successfully.

File sizes after gzip:

  49.84 KB  build/static/js/2.5d7960d6.chunk.js
  1.48 KB   build/static/js/main.70809ac3.chunk.js
  777 B     build/static/js/runtime-main.762c8e5c.js
  580 B     build/static/css/main.eab258ed.chunk.css

The project was built assuming it is hosted at /.
You can control this with the homepage field in your package.json.

The build folder is ready to be deployed.
You may serve it with a static server:

  npm install -g serve
  serve -s build

Find out more about deployment here:

  https://cra.link/deployment