dfinity / sdk

IC SDK: a Software Development Kit for creating and managing canister smart contracts on the ICP blockchain.
https://internetcomputer.org/developers
Apache License 2.0
177 stars 85 forks source link

Feature request: support `"build"` field for `"type": "asset"` #2467

Closed paulyoung closed 7 months ago

paulyoung commented 2 years ago

As mentioned in https://github.com/dfinity/sdk/issues/2199#issuecomment-1221118120:

I'm surprised that doesn't work; the assets need to get built somehow, and having something like "build": "npm run build" seems very reasonable.

Please consider adding this feature. Thanks to the maintainers of dfx for all of your hard work.

paulyoung commented 2 years 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.

sesi200 commented 2 years ago

Internal ticket: SDK-704

JamesMcGuigan commented 2 years ago

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"
yomanthunder commented 1 year ago

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??

sesi200 commented 1 year ago

Sounds like you haven't configured a build command in your frontend project

dfx-json commented 7 months ago

This is available, starting with dfx version 0.14.1