create-figma-plugin
create-figma-plugin copied to clipboard
Building with 3.0.2 fails on Windows if there's a `build-figma-plugin.ui.cjs` file in the repo
I think this is #77 all over again. The build-figma-plugin.ui.cjs
file is just this:
module.exports = (buildOptions) => ({
...buildOptions,
keepNames: true,
});
When it's in the main directory, npm run build
fails with this error:
info Typechecking...
success Typechecked in 2.048s
info Building...
error esbuild error
Only URLs with a scheme in: file, data are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'
npm ERR! Lifecycle script `build` failed with error:
npm ERR! Error: command failed
npm ERR! in workspace: [email protected]
npm ERR! at location: C:\...\test
When the config file is removed, the build works, but the plugin doesn't, because it needs to pass keepNames: true
to esbuild. (As an aside, it would be nice if this sort of config, as well as the manifest, could be passed on the command line, which would then avoid this problem.)
I don’t have a Windows machine so I can’t properly debug this. Would the fix be to specify keepNames: true
when esbuild detects that it is running in Windows?
No, that was just something I happened to need to add for a library I'm working on. The issue is having any config file at all on Windows. Having a config worked in 2.6.1, but failed when I updated.
I haven't investigated, but based on this comment, something may have been fixed previously: https://github.com/yuanqing/create-figma-plugin/issues/77#issuecomment-1141987346
Just to confirm, the contents of the build-*
files doesn't matter. It can be completely empty. Just its existence causes the error, since it occurs while trying to load the file, before it's executed.
I have the same problem here on a Windows machine. If there exists any build-figma-plugin.main.js or build-figma-plugin.ui.js config file then the build fails with: error esbuild error Only URLs with a scheme in: file and data are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'd:'
The content of the config file does not matter.
There seems to be a problem with resolving the path on Windows. Building is not possible until this is fixed.
Anything we can do to help fix this? I was just thinking about trying to add some values via a .env
file, as described in this comment, but there's no way to add a build config on Windows due to this bug.
@fwextensions @janweigel – Happy to review and merge a PR if any of you would like to work on a fix!
From the error message you shared, my suspicion is that the absolute path returned by globby
in this line of code in the build-bundles-async.ts
file is the root cause of the problem:
https://github.com/yuanqing/create-figma-plugin/blob/d8238d3589e7f52587a1d86b926855bcf49a3c86/packages/build/src/utilities/build-bundles-async/build-bundles-async.ts#L51
Is the fix here to add a file://
prefix to the path when running on Windows?
@yuanqing yes, that's what was needed. I tested on my Windows machine, this is working for me: https://github.com/yuanqing/create-figma-plugin/pull/211
Same problem here (Windows 10):
> build-figma-plugin --typecheck --minify
info Typechecking...
success Typechecked in 1.114s
info Building...
error esbuild error
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:'
i'm having the same issue here on Windows 11. i'm blocked... any ideas how to fix this?
info Building... error esbuild error 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:' success Typechecked in 2.726s info Watching...
@kikobr https://github.com/yuanqing/create-figma-plugin/pull/211