Home > Mobile >  Node complain about import library when its all there
Node complain about import library when its all there

Time:11-03

Im trying to write a node script using a third party library (@craftzing/akeneo-api) and even before using the library, just at the import statement I get an error as its missing a module. It does find the akeneo-api module, but this module itself imports from its own files a http-client and it fails to import this (even if the file is there). I tried commenting the http-client import to see if it was a particular problem with it, but it fails with the next import, so for some reason it is failing to load the imports inside of the library I am using.

Any ideas?

% node scripts/sync.js
node:internal/errors:477
    ErrorCaptureStackTrace(err);
    ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/test/scripts/node_modules/@craftzing/akeneo-api/dist/mjs/http-client' imported from /Users/test/scripts/node_modules/@craftzing/akeneo-api/dist/mjs/index.js
    at new NodeError (node:internal/errors:387:5)
    at finalizeResolution (node:internal/modules/esm/resolve:429:11)
    at moduleResolve (node:internal/modules/esm/resolve:1006:10)
    at defaultResolve (node:internal/modules/esm/resolve:1214:11)
    at nextResolve (node:internal/modules/esm/loader:165:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:844:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:431:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)
    at link (node:internal/modules/esm/module_job:75:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}

This is the script so far (just the import)

import client from '@craftzing/akeneo-api';
console.log('test');

CodePudding user response:

You should be able to resolve the issue by including --es-module-specifier-resolution=node in your node command. As in

node --es-module-specifier-resolution=node scripts/sync.js
  • Related