ag-psd
ag-psd copied to clipboard
Cannot find module "ag-psd\initialize-canvas"
I tried running one of the examples but I get this error. Not sure what it happens.
Error:
`internal/process/esm_loader.js:74 internalBinding('errors').triggerUncaughtException( ^
Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'C:\Users\Stephane\WebstormProjects\MyProject\node_modules\ag-psd\initialize-canvas' imported from C:\Users\Stephane\WebstormProjects\MyProject\data\templates\custom_2.js
Did you mean to import ag-psd/initialize-canvas.js?
at new NodeError (internal/errors.js:322:7)
at finalizeResolution (internal/modules/esm/resolve.js:308:11)
at moduleResolve (internal/modules/esm/resolve.js:731:10)
at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:842:11)
at Loader.resolve (internal/modules/esm/loader.js:89:40)
at Loader.getModuleJob (internal/modules/esm/loader.js:242:28)
at ModuleWrap.
See code below:
`import * as fs from 'fs'; import 'ag-psd/initialize-canvas'; // only needed for writing image data and thumbnails import { writePsdBuffer } from 'ag-psd';
const psd = { width: 300, height: 200, children: [ { name: 'Layer #1', } ] };
const buffer = writePsdBuffer(psd); fs.writeFileSync('my-file.psd', buffer);`
I think these imports are going to work only in Typescript
just change it to
const fs = require('fs');
require('ag-psd/initialize-canvas'); // only needed for writing image data and thumbnails
const { writePsdBuffer } = require('ag-psd');
Thanks for your reply. Now, it says "ReferenceError: require is not defined in ES module scope, you can use import instead". I've temporarily fixed it by using the absolute path.
The library is not an ES module, so it probably has some issues when using with node.js ES modules