esbuild-plugins: Copy plugin "is not a function"
I’m working on an esbuild configuration and want to copy a file (manifest.json) to a specific folder when I build my project for testing purposes. I included the copy plugin into my esbuild-config.mjs
import esbuild from "esbuild";
import process from "process";
import builtins from 'builtin-modules'
import copy from 'esbuild-plugin-copy';
const prod = (process.argv[2] === 'production');
const baseConfig = {
// ...
};
const testVaultPluginFolder = 'test-vault/.obsidian/plugins/obsidian-sample-plugin/';
const devConfig = {
...baseConfig,
outfile: testVaultPluginFolder + 'main.js',
plugins: [
copy({ // <- This line causes the problem
assets: [
{ from: ['manifest.json'], to: [testVaultPluginFolder] }
]
})
]
};
const prodConfig = {
...baseConfig,
outfile: 'main.js',
};
if (prod){
esbuild.build(prodConfig).catch(() => process.exit(1));
} else {
esbuild.build(devConfig).catch(() => process.exit(1));
}
I can even Ctrl + Click into the copy function in VS Code.
Then when I run it it tells me that copy is not a function:
$ npm run dev
> obsidian-sample-plugin@1.1.0 dev C:\Workspaces\RNSS-Sample\obsidian-sample-plugin
> node esbuild.config.mjs
file:///C:/Workspaces/.../obsidian-sample-plugin/esbuild.config.mjs:59
copy({
^
TypeError: copy is not a function
at file:///C:/Workspaces/.../obsidian-sample-plugin/esbuild.config.mjs:59:3
at ModuleJob.run (internal/modules/esm/module_job.js:170:25)
at async Loader.import (internal/modules/esm/loader.js:178:24)
at async Object.loadESM (internal/process/esm_loader.js:68:5)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! obsidian-sample-plugin@1.1.0 dev: `node esbuild.config.mjs`
npm ERR! Exit status 1
Edit: Further research
I found this question where the copy (to clipboard) function produced the same error: https://stackoverflow.com/questions/62212958/devtools-console-copy-is-not-a-function-while-on-youtube
The problem was, that the DOM contained another element named copy that was not a function. Even though I’m not in a Browser here, I tried renaming the import.
import copyIsADamnFunction from 'esbuild-plugin-copy';
plugins: [
copyIsADamnFunction({
assets: [
{ from: ['manifest.json'], to: [testVaultPluginFolder] }
]
})
]
Same result:
TypeError: copyIsADamnFunction is not a function
at file:///C:/Workspaces/.../obsidian-sample-plugin/esbuild.config.mjs:59:3
When I remove the import I get
ReferenceError: copy is not defined
at file:///C:/Workspaces/.../obsidian-sample-plugin/esbuild.config.mjs:58:11
So the import imports something. And VS Code tells me on mouse over that copy is a function with one optional parameter returning a esbuild.Plugin:
(alias) copy(options?: Partial<Options>): esbuild.Plugin
import copy
If I write copy. VS Code even offers me code completion like apply, arguments, bind and call which all belong to Function.prototype. How can copy not be a function?
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 22 (11 by maintainers)
Can you provide some more precise information, including what you mean by not working, and your directory structure? You can also upgrade to
1.2.1add use the newdryRunoption to see what’s happenning.I’m always here to help.
I think maybe we can add new option
resolveFromwhich acceptscwd|outor any other path string, and this option will be used to resolve finalasset.topath, do you think this could help?@uncle-ara @RobinNiemann The latest release 0.5.1 should have fixed the problem as I’m now using the pure
tscas compiler.Both named import and default import are supported.
Seems like problem lead by incorrect compiler options, this will be fixed in next version which will released soon this weekend.