Open wszgrcy opened 6 months ago
The root cause is diegomura/react-pdf#2624 here, where the mentioned package does not expose its browser bundle to modern ESM bundlers.
ng serve
uses Vite's prebundling by default which has its own behavior w.r.t. how modules and imports are processed, potentially resulting in differences compared to ng build
. I suppose you'd get the same error if you set "prebundle": false
in the "options"
of the application builder.
The root cause is diegomura/react-pdf#2624 here, where the mentioned package does not expose its browser bundle to modern ESM bundlers.
ng serve
uses Vite's prebundling by default which has its own behavior w.r.t. how modules and imports are processed, potentially resulting in differences compared tong build
. I suppose you'd get the same error if you set"prebundle": false
in the"options"
of the application builder.
I find react-pdf has browser version "./node_modules/@react-pdf/pdfkit/lib/pdfkit.browser.min.js"
,But I don't know how to replace it, using 'paths' to replace it doesn't work
tsconfig.json
"paths": {
"@cyia/ngx-bridge": [
// "./projects/bridge"
"./dist/bridge"
],
"@react-pdf/pdfkit": [
"./node_modules/@react-pdf/pdfkit/lib/pdfkit.browser.min.js"
]
},
error
X [ERROR] Could not resolve "fs"
node_modules/@react-pdf/pdfkit/lib/pdfkit.js:9:15:
9 │ import fs from 'fs';
╵ ~~~~
The package "fs" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
tsconfig
paths don't apply to how JS modules are resolved, it only affects how your app's TypeScript imports are resolved.
I don't know of a way to workaround https://github.com/diegomura/react-pdf/issues/2624, the package has to expose its browser bundle in its exports
specification otherwise it cannot be used.
tsconfig
paths don't apply to how JS modules are resolved, it only affects how your app's TypeScript imports are resolved.I don't know of a way to workaround diegomura/react-pdf#2624, the package has to expose its browser bundle in its
exports
specification otherwise it cannot be used.
thanks .I think there are other ways to solve it
There is definitely some misalignment here between the ng serve
and ng build
, however the errors are correct on ng build
.
I solved my problem with externalDependencies (but broke ng serve):
// angular.json:
"builder": "@angular-devkit/build-angular:application",
"options": {
"externalDependencies": ["./node/extend.js", "./node/self.js"],
But those files (./node/extend.js" and ./node/self.js) are listed in the corresponding package.json/browser
key:
"browser": {
"./dist/node/extend.js": false,
"./dist/node/self.js": false,
esbuild reads it and ignores it. But it's not working with esbuild from ng-cli
generated project.
any update on this ?
same issue using paper.js … the modern esbuild option is just not the right choice if you need packages that aren't using the latest bundling approaches?
Command
build
Is this a regression?
The previous version in which this bug was not present was
No response
Description
I did not encounter any errors regarding node references during development, but the following errors occurred during build
Minimal Reproduction
default angular.json
Exception or Error
Your Environment
Anything else relevant?
No response