box-node-sdk
box-node-sdk copied to clipboard
Is box-node-sdk compatible with ES6 import ?
- [X] I have checked that the SDK documentation doesn't solve my issue.
- [X] I have checked that the API documentation doesn't solve my issue.
- [X] I have searched the Box Developer Forums and my issue isn't already reported (or if it has been reported, I have attached a link to it, for reference).
- [X] I have searched Issues in this repo and my issue isn't already reported.
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
- % npm init lwr
- % cd lwr-project
- % yarn add box-node-sdk
- 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'
- % yarn install
- % yarn dev
- 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
Hi @RupertBarrow,
Thanks for submitting this Issue! Currently we don't support ES6 modules but we plan to change this.
Until then please use this:
BoxSDK = require('box-node-sdk');
@arjankowski
it perfectly works but change your import
import BoxSDK from 'box-node-sdk';
@RupertBarrow Is there is anything else which I can help?
@arjankowski Thanks for the answer. What is the plan to support ES6 modules ? Is this lead by Box or by the community ?
@huineng Thanks for chipping in. Your solution does not work for me. Do you have an implementation where this works ? Would you care to share your package.json and other configuration files ? This would be a great help.
Hi @RupertBarrow, I created a new ticket for this issue and I will raise this topic on our next SDK planning meeting. Then I will back to you with more info.
box-node-sdk is lead by Box. Please look here for more details https://github.com/box/sdks.
[internal jira ticket: SDK-2072]
it perfectly works but change your import
import BoxSDK from 'box-node-sdk';
Hi @huineng can you please provide more details on how you were able to resolve this error through
import BoxSDK from 'box-node-sdk';
For me it is still not working.
i'm using webpack with module es6 / esnext, i'm only doing imports (never require)
i'm using webpack with module es6 / esnext, i'm only doing imports (never require)
@huineng can you provide a snippet of your webpack.config.js?
This issue has been automatically marked as stale because it has not been updated in the last 30 days. It will be closed if no further activity occurs within the next 7 days. Feel free to reach out or mention Box SDK team member for further help and resources if they are needed.
not sure if this is still an issue , but there is a d.ts file available so you import it under whatever name you want
export = BoxSDKNode;
![image](https://user-images.githubusercontent.com/3482445/208647648-ba34d042-c2c5-4a9b-bdaa-1870ad51658b.png)
Hi @arjankowski , could you tell us about progress on the ticket linked to this issue ?
Hi @RupertBarrow, we have decided not to add ES6 import support to the current version of box-node-sdk at this time. That's because we're working on a new, refreshed version of our SDK. Wanting to release it as soon as possible, this is where we concentrate our forces.
The new version should support ES6 imports
Hi @arjankowski , where can we see or read about this new SDK ?