I am importing an external package into a CyberChef custom operation. I am not sure how I should import the package. The package is not published but is link using a file:./...
dependency.
From CyberChef
MyOperation.mjs
import SystemDatabase from "test-db";
My external package
package.json
{
"name": "test-db",
...
"main": "src/main.js",
...
}
main.js
import SystemDatabase from "./SystemDatabase.js";
module.exports = {
SystemDatabase
};
SystemDatabase.js
class SystemDatabase {
// ...
}
module.exports = {
SystemDatabase
};
Build error
This is the error I don’t understand.
ERROR in ../[REDACTED]/test-db/src/SystemDatabase.js 2:0-62
Module not found: Error: Can't resolve '@babel/runtime/helpers/createClass' in '[REDACTED]/test-db/src'
resolve '@babel/runtime/helpers/createClass' in '[REDACTED]/test-db/src'
Parsed request is a module
using description file: [REDACTED]/test-db/package.json (relative path: ./src)
Field 'browser' doesn't contain a valid alias configuration
resolve as module
[REDACTED]/test-db/src/node_modules doesn't exist or is not a directory
[REDACTED]/test-db/node_modules doesn't exist or is not a directory
[REACTED]/node_modules doesn't exist or is not a directory
...
@ ../[REACTED]/test-db/src/main.js 2:0-47 4:2-15
@ ./src/core/operations/MyOperation.mjs 15:0-44
@ ./src/core/config/modules/MyModule.mjs 12:0-69 22:18-34
Follow-up
After installing babel-runtime to my external package. I now get the runtime error:
ES Modules may not assign module.exports or exports.*, Use ESM export syntax
If I use export default syntax, I get :
SyntaxError: Cannot use import statement outside a module
I want my package to import in all JS project types.