compute-js-static-publish
compute-js-static-publish copied to clipboard
fix: Windows compatibility issues
Hi!
While I'm not a Windows user, I have some colleagues at IKEA who have bumped into issues with this library. It's the same underlying issue that caused https://github.com/fastly/next-compute-js/issues/1
I've added two fixes that makes this library work on Windows:
1. await import()
await import()
doesn't seem to work when you use an absolute path like C:\Users\Johan\IKEA-PROJECT\compute-js\static-publish.rc.js
. You'll get the following error:
Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'
The solution is https://nodejs.org/api/url.html#url_url_pathtofileurl_path. The path then becomes file:///C:/Users/Johan/IKEA-PROJECT/compute-js/static-publish.rc.js
.
2. \path\to\file.css vs. /path/to/file.css
assetKeys end up with \
in Windows, so request URLs never match against any assets.
Feel free to incorporate these changes any way you see fit!
PS C:\Documents\Fastly-Compute-javascript-doh-cache\compute-js> fastly compute serve
✓ Verifying fastly.toml
✓ Identifying package name
✓ Identifying toolchain
✗ Running [scripts.build]
INFO: Command output:
--------------------------------------------------------------------------------
> @masx200/[email protected] prebuild
> npx @fastly/compute-js-static-publish --build-static
Fastly Compute JavaScript Static Publisher
✅ Created publish ID
Publish ID: Gj5r892RPiHK8x8WtQqSZ
🚀 Building loader...
❌ Can't load static-publish.rc.js
Run this from a compute-js-static-publish compute-js directory.
Unable to load C:\Documents\Fastly-Compute-javascript-doh-cache\compute-js\static-publish.rc.js
--------------------------------------------------------------------------------
ERROR: error during execution process (see 'command output' above): exit status 1.
Here are some steps you can follow to debug the issue:
- Re-run the fastly command with the --verbose flag to see more information.
- Is the required language toolchain (node/npm, rust/cargo etc) installed correctly?
- Is the required version (if any) of the language toolchain installed/activated?
- Were the required dependencies (package.json, Cargo.toml etc) installed?
- Did the build script (see fastly.toml [scripts.build]) produce a ./bin/main.wasm binary file?
- Was there a configured [scripts.post_build] step that needs to be double-checked?
For more information on fastly.toml configuration settings, refer to https://www.fastly.com/documentation/reference/compute/fastly-toml
Tested it and this fixes the above issue I am having on Windows systems, @harmony7 could this be merged?
Hi, thanks for the discussion and pull request. Will be taking a look at this soon, expect a release by next week.
This has been released in 6.1.1.