web3-storage / web3.storage

DEPRECATED ⁂ The simple file storage service for IPFS & Filecoin
https://web3.storage
Other
501 stars 121 forks source link

SyntaxError: Unexpected token '.' #310

Closed tomploem closed 3 years ago

tomploem commented 3 years ago

I am trying to use web3 storage in a NodeJS (Express) application. The application can not start due to following error:

.../node_modules/@web-std/fetch/dist/index.cjs:1534
response_?.emit("error", err);
                                          ^
SyntaxError: Unexpected token '.'

I tried to use the library with node 14.x and 16.x but had no success so far. Any tips on how to use the library in a backend service?

alanshaw commented 3 years ago

Looks like it's failing because of the ?...but this should be working in Node.js 16.

tomploem commented 3 years ago

Would you be able to provide an example project similar to the image-gallery frontend app? I might be missing some small details here 🤔

coolcorexix commented 3 years ago

I also experience this error... I am using the code snippet shared from https://docs.web3.storage/#create-the-upload-script but using node 16 does solve the problem

alanshaw commented 3 years ago

@tomploem @coolcorexix according to https://node.green/#ES2020 Node.js 14 supports "optional chaining operator (?.)" please can you double check you are using Node.js 14 or 16 with node --version?

tomploem commented 3 years ago

Hey @alanshaw, i can confirm the error is happening with v14 and v16. My application compiles from typescript so it might have something to do with this?

Does it work on your machine with v14 or higher?

coolcorexix commented 3 years ago

@tomploem in that case, I would need you to share your tsconfig.json and the command you use for running the web3storage script. Because typescript allow user to specify target and module so there's high chance your config crash the command

alanshaw commented 3 years ago

@tomploem do you have some code I can look at to double check?

dchoi27 commented 3 years ago

Hey folks - closing for now, but please reopen if you're still experiencing this and when you get a chance to add more detail!