ag-psd icon indicating copy to clipboard operation
ag-psd copied to clipboard

Cannot find module "ag-psd\initialize-canvas"

Open stephanecoder opened this issue 3 years ago • 3 comments

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. (internal/modules/esm/module_job.js:76:40) at link (internal/modules/esm/module_job.js:75:36) { code: 'ERR_MODULE_NOT_FOUND' }`

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);`

stephanecoder avatar Nov 12 '21 15:11 stephanecoder

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');

Agamnentzar avatar Nov 12 '21 16:11 Agamnentzar

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.

stephanecoder avatar Nov 12 '21 17:11 stephanecoder

The library is not an ES module, so it probably has some issues when using with node.js ES modules

Agamnentzar avatar Nov 12 '21 17:11 Agamnentzar