Skip to content

Is box-node-sdk compatible with ES6 import ? #708

@RupertBarrow

Description

@RupertBarrow

Description of the Issue

I am importing box-node-sdk into an ES6 Node application and am getting an error at "compile"-time when packaging

node_modules/vm2/lib/resolver-compat.js:169:33: error: Could not resolve "async_hooks" (set platform to "node" when building for node)
169 │ const {AsyncResource} = require('async_hooks');

Steps to Reproduce

  1. % npm init lwr
  2. % cd lwr-project
  3. % yarn add box-node-sdk
  4. Edit lwr-project/src/modules/example/app/app.js and add the following line at the top of the file :
    import { BoxSDK } from 'box-node-sdk'
  5. % yarn install
  6. % yarn dev
  7. Open http://localhost:3000 : this starts the compilation/packaging process

LWR reference documentation :
https://developer.salesforce.com/docs/platform/lwr/guide/lwr-intro.html

Expected Behavior

The application should compile/get packaged correctly

Error Message, Including Stack Trace

rupert@MacBook-Pro-de-Rupert lwr-project % yarn dev
yarn run v1.22.17
$ lwr serve
server running at: port: 3000 | mode: dev
Watching: /Users/rupert/Workspaces/test/lwr-project/src/modules/example/app/app.js

node_modules/vm2/lib/resolver-compat.js:29:8: warning: This call to "require" will not be bundled because the argument is not a string literal (surround with a try/catch to silence this warning)
29 │ return require(/* webpackIgnore: true */ moduleName);
╵ ~~~~~~~

node_modules/vm2/lib/resolver-compat.js:169:33: error: Could not resolve "async_hooks" (set platform to "node" when building for node)
169 │ const {AsyncResource} = require('async_hooks');
╵ ~~~~~~~~~~~~~

[ERROR]resolveNpmModules(esbuild): {
specifier: 'box-node-sdk',
dest: '/Users/rupert/Workspaces/test/lwr-project/lwr_cache/web_modules'
}
LWR Diagnostic Error: 404: Could not find module entry with specifier "box-node-sdk"

[
{
description: {
category: 'lwrUnresolvable/module',
advice: [],
message: '404: Could not find module entry with specifier "box-node-sdk"'
}
}
]
DiagnosticsError: 404: Could not find module entry with specifier "box-node-sdk"

at createSingleDiagnosticError (file:///Users/rupert/Workspaces/test/lwr-project/node_modules/@lwrjs/diagnostics/build/es/errors.js:6:12)
at LwrModuleRegistry.delegateGetModuleEntryOnServices (file:///Users/rupert/Workspaces/test/lwr-project/node_modules/@lwrjs/module-registry/build/es/index.js:214:15)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async resolveExternalImport (file:///Users/rupert/Workspaces/test/lwr-project/node_modules/@lwrjs/module-registry/build/es/module-record.js:39:35)
at async getModuleRecord (file:///Users/rupert/Workspaces/test/lwr-project/node_modules/@lwrjs/module-registry/build/es/module-record.js:80:44)
at async LwrModuleRegistry.createModuleDefinition (file:///Users/rupert/Workspaces/test/lwr-project/node_modules/@lwrjs/module-registry/build/es/index.js:103:30)
at async getModuleGraphs (file:///Users/rupert/Workspaces/test/lwr-project/node_modules/@lwrjs/shared-utils/build/es/graph.js:117:11)
at async file:///Users/rupert/Workspaces/test/lwr-project/node_modules/@lwrjs/view-registry/build/es/linkers/legacy_view_bootstrap.js:107:23
at async Promise.all (index 0)
at async getHtmlResources (file:///Users/rupert/Workspaces/test/lwr-project/node_modules/@lwrjs/view-registry/build/es/linkers/legacy_view_bootstrap.js:106:5)

Screenshots

Versions Used

Node SDK: 2.0.0
The problem does not seem to occur with box-node-sdk 1.39.0

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions