Closed paulyoung closed 7 months ago
@krpeacock said in https://github.com/dfinity/sdk/issues/2199#issuecomment-1222560199:
It currently runs
npm run build
for asset canisters, but there's no reason we can't make that customizable
@krpeacock that would be great. I think the current behavior is surprising; dfx build myproject_assets
doesn’t appear to do anything at all.
I'm currently trying to get dfx build
working with Yew (Rust React) with a custom build step for trunk build --release
which deploys into ./dist/
(Trunk is Rust Webpack)
The counter_yew
child canister is configured in dfx.json
as "type": "assets"
.
Attempting your suggestion of
rust/counter/src/counter_yew/package.json::scripts::build: "trunk build --release"
fails with the error message:
The post-build step failed for canister 'ryjl3-tyaaa-aaaaa-aaaba-cai' (counter_yew) with an embedded error: Failed to assert source paths.: Unable to determine canonical location of asset source path /Users/jamie/code/github/icp_examples/rust/counter/src/counter_yew/dist/: No such file or directory (os error 2)
It appears that npm run build
is not being triggered for the package.json file inside the counter_yew
child canister. Creating an empty ./dist/
directory avoids the error message, but doesn't trigger any build assets.
The workaround is to put the build script in the parent package.json
file, which does seem to work
rust/counter/package.json::scripts::build: "cd src/counter_yew; trunk build --release"
A final observation is that if the parent package.json is missing a script::build
field, then dfx build
fails as follows
Building frontend...
Error: Failed while trying to build all canisters.
Caused by: Failed while trying to build all canisters.
The post-build step failed for canister 'ryjl3-tyaaa-aaaaa-aaaba-cai' (counter_yew) with an embedded error: Failed to build frontend for network 'local'.: The command '"npm" "run" "build"' failed with exit status 'exit status: 1'.
Stdout:
Stderr: npm ERR! Missing script: "build"
Error: The post-build step failed for canister 'ryjl3-tyaaa-aaaaa-aaaba-cai' with an embedded error: The command '"npm" "run" "build"' failed with exit status 'exit status: 1'. Stdout:
Stderr: npm ERR! Missing script: "build" npm ERR! npm ERR! To see a list of scripts, run: npm ERR! npm run
npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\SHRISHVESH\AppData\Local\npm-cache_logs\2023-06-30T08_26_53_922Z-debug-0.log how should i fix this issue??
Sounds like you haven't configured a build
command in your frontend project
This is available, starting with dfx version 0.14.1
As mentioned in https://github.com/dfinity/sdk/issues/2199#issuecomment-1221118120:
Please consider adding this feature. Thanks to the maintainers of
dfx
for all of your hard work.