box-node-sdk icon indicating copy to clipboard operation
box-node-sdk copied to clipboard

Is box-node-sdk compatible with ES6 import ?

Open RupertBarrow opened this issue 2 years ago • 8 comments

  • [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

  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

RupertBarrow avatar Mar 14 '22 15:03 RupertBarrow

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

arjankowski avatar Mar 14 '22 16:03 arjankowski

it perfectly works but change your import

import BoxSDK from 'box-node-sdk';

huineng avatar Mar 14 '22 17:03 huineng

@RupertBarrow Is there is anything else which I can help?

arjankowski avatar Mar 14 '22 17:03 arjankowski

@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.

RupertBarrow avatar Mar 15 '22 09:03 RupertBarrow

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]

arjankowski avatar Mar 15 '22 14:03 arjankowski

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.

abdulhaseeb07a avatar Apr 11 '22 11:04 abdulhaseeb07a

i'm using webpack with module es6 / esnext, i'm only doing imports (never require)

huineng avatar Apr 11 '22 17:04 huineng

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?

abdulhaseeb07a avatar Apr 13 '22 06:04 abdulhaseeb07a

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.

stale[bot] avatar Dec 19 '22 19:12 stale[bot]

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

huineng avatar Dec 20 '22 10:12 huineng

Hi @arjankowski , could you tell us about progress on the ticket linked to this issue ?

RupertBarrow avatar Dec 20 '22 15:12 RupertBarrow

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

arjankowski avatar Dec 22 '22 14:12 arjankowski

Hi @arjankowski , where can we see or read about this new SDK ?

RupertBarrow avatar Mar 21 '23 22:03 RupertBarrow