crypto-api icon indicating copy to clipboard operation
crypto-api copied to clipboard

Add file extensions to imports to support node 12

Open n1474335 opened this issue 5 years ago • 1 comments

In Node 12, extensions are required on all import statements so that Node knows whether to treat it as a module (mjs) or a script (js).

Currently, running crypto-api in Node 12 gives the following error:

>> internal/modules/esm/default_resolve.js:59
>>   let url = moduleWrapResolve(specifier, parentURL);
>>             ^
>> 
>> Error: Cannot find module '/node_modules/crypto-api/src/hasher/has160' imported from /node_modules/crypto-api/src/crypto-api.mjs
>>     at Loader.resolve [as _resolve] (internal/modules/esm/default_resolve.js:59:13)
>>     at Loader.resolve (internal/modules/esm/loader.js:73:33)
>>     at Loader.getModuleJob (internal/modules/esm/loader.js:149:40)
>>     at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:43:40)
>>     at link (internal/modules/esm/module_job.js:42:36) {
>>   code: 'ERR_MODULE_NOT_FOUND'
>> }

Changing all your imports to specify the file extension will solve this.

n1474335 avatar Jul 09 '19 11:07 n1474335

This is currently causing some issues in CyberChef and preventing our API from working correctly (see https://github.com/gchq/CyberChef/pull/600). Is there any way this could be fixed soon?

crypto-api is a really great library and I believe we use almost everything it provides so it would be a shame to have to move away from it.

n1474335 avatar Aug 12 '19 13:08 n1474335