Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting a syntax error when trying to run example typescript file #1051

Open
JonoSuave opened this issue Dec 20, 2022 · 4 comments
Open

Getting a syntax error when trying to run example typescript file #1051

JonoSuave opened this issue Dec 20, 2022 · 4 comments

Comments

@JonoSuave
Copy link

I edited the team-as-user.ts file and tried to run the following from the typescript directory (i.e. node team-as-user/team-as-user.ts):
import { Dropbox } from "dropbox";

const accessToken =
"sl.****";

const dbx = new Dropbox({ accessToken });
dbx
.teamMembersList({
limit: 500,
include_removed: false,
})
.then((data) => {
console.log(data);
});

I got the following error:
import { Dropbox } from "dropbox";
^^^^^^

SyntaxError: Cannot use import statement outside a module
at wrapSafe (internal/modules/cjs/loader.js:1001:16)
at Module._compile (internal/modules/cjs/loader.js:1049:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Function.executeUserEntryPoint [as runimport { Dropbox } from "dropbox";
^^^^^^

SyntaxError: Cannot use import statement outside a module
at wrapSafe (internal/modules/cjs/loader.js:1001:16)
at Module._compile (internal/modules/cjs/loader.js:1049:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)

I also ran npm run build successfully and still the same error. What am I doing wrong?

@greg-db
Copy link
Contributor

greg-db commented Dec 21, 2022

Thanks for writing this in and apologies for the trouble.

Please try it out like this and let us know if that does or doesn't help:

$ cd dropbox-sdk-js
$ npm install
$ npm run build:cjs
$ cd examples
$ cd typescript
$ npm install # needed to reference dbx in ancestor folder
$ node team-as-user # or any other example

@JonoSuave
Copy link
Author

JonoSuave commented Dec 21, 2022

That's good progress. How do I recompile the index.js file within the team-as-user folder?

@JonoSuave
Copy link
Author

Looks like I had to rename the team-as-user.ts file to index.js and include the source mapping comment at the bottom to get the tsc transpiler to update the index.js correctly.

@greg-db
Copy link
Contributor

greg-db commented Dec 22, 2022

Thanks for following up. I'm glad to hear you got this working.

For reference though, the team took a look and said that you may want to:

  1. Run npm run build in examples/typescript
  2. Run node dist/team-as-user/team-as-user

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants