Posting here as I had a different cause.
For me, I was using AWS Amplify, which uses AWS CodeBuild behind the scenes.
I had modified some of my dependencies, devDependencies, and peerDependencies for multiple packages in a monorepo.
The build failed because my web app was trying to pull in an old version of the entities
library, way down in the dependency tree.
$ pnpm why entities
html-react-parser 3.0.9
└─┬ html-dom-parser 3.1.3
└─┬ htmlparser2 8.0.1
├─┬ domutils 3.0.1
│ └─┬ dom-serializer 2.0.0
│ └── entities 2.2.0
└── entities 2.2.0
Resulting in this CI/CD build error:
2023-02-22T05:39:28.319Z [INFO]: @myapp/webapp:build: cache miss, executing cd449f2fbd550ffc
2023-02-22T05:39:28.775Z [INFO]: @myapp/webapp:build:
@myapp/webapp:build: > @myapp/webapp@0.1.0 build /codebuild/output/src711556549/src/myapp/apps/webapp
@myapp/webapp:build: > react-scripts build
@myapp/webapp:build:
2023-02-22T05:39:28.952Z [INFO]: @myapp/webapp:build: node:internal/modules/cjs/loader:560
@myapp/webapp:build: throw e;
@myapp/webapp:build: ^
@myapp/webapp:build:
@myapp/webapp:build: Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/decode_codepoint' is not defined by "exports" in /codebuild/output/src711556549/src/myapp/node_modules/.pnpm/node_modules/entities/package.json
@myapp/webapp:build: at new NodeError (node:internal/errors:387:5)
@myapp/webapp:build: at throwExportsNotFound (node:internal/modules/esm/resolve:365:9)
@myapp/webapp:build: at packageExportsResolve (node:internal/modules/esm/resolve:649:3)
2023-02-22T05:39:28.953Z [INFO]: @myapp/webapp:build: at resolveExports (node:internal/modules/cjs/loader:554:36)
@myapp/webapp:build: at Function.Module._findPath (node:internal/modules/cjs/loader:594:31)
@myapp/webapp:build: at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1007:27)
@myapp/webapp:build: at Function.Module._load (node:internal/modules/cjs/loader:866:27)
@myapp/webapp:build: at Module.require (node:internal/modules/cjs/loader:1093:19)
@myapp/webapp:build: at require (node:internal/modules/cjs/helpers:108:18)
@myapp/webapp:build: at Object.<anonymous> (/codebuild/output/src711556549/src/myapp/node_modules/.pnpm/node_modules/htmlparser2/lib/Tokenizer.js:6:42) {
@myapp/webapp:build: code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
@myapp/webapp:build: }
2023-02-22T05:39:28.957Z [INFO]: @myapp/webapp:build: ELIFECYCLE Command failed with exit code 1.
2023-02-22T05:39:28.962Z [WARNING]: @myapp/webapp:build: ERROR: command finished with error: command (/codebuild/output/src711556549/src/myapp/apps/webapp) pnpm run build exited (1)
2023-02-22T05:39:28.962Z [WARNING]: command (/codebuild/output/src711556549/src/myapp/apps/webapp) pnpm run build exited (1)
ERROR run failed: command exited (1)
It took me a while to realize that, in my build settings, the build was caching node_modules:
cache:
paths:
- node_modules/**/*
The solution, I just needed to comment the about build settings line, kick off another build, then un-comment.
cache:
paths:
# - node_modules/**/*
After the build succeeded, I restored this caching of the node_modules so that future CI/CD builds would be potentially faster.
The correct dependency tree:
$ pnpm why entities
html-react-parser 3.0.9
└─┬ html-dom-parser 3.1.3
└─┬ htmlparser2 8.0.1
├─┬ domutils 3.0.1
│ └─┬ dom-serializer 2.0.0
│ └── entities 4.4.0
└── entities 4.4.0
See build setting info here:
https://docs.aws.amazon.com/amplify/latest/userguide/build-settings.html#yml-specification-syntax