Astro Cloudflare Pages SyntaxError: Unexpected token 'with'
I got this error recently when cloudflare pages build my code
![No description](https://cdn.answeroverflow.com/1263458765366235196/Screenshot_2024-07-18_at_5.03.47_PM.png)
13 Replies
guessing astro are using import with attribute now?
https://github.com/tc39/proposal-import-attributes
not sure your node version but i'd try updating it
Detected the following tools from environment: pnpm@8.7.1, nodejs@18.17.1
eh 18 should be fine using with afaik? but may be worth trying 20 - not fully sure what node vers support it (and what versions of it)
ah yes 18.17 is too old
done fixing it with v21.7.1
it's still expecting
import json from './file.json' assert { type: 'json' }
instead of import json from './file.json' with { type: 'json' }
Just set the ENV variable NODE_VERSION 21.7.1 and rebuild and it is successfully build
https://nodejs.org/api/esm.html#import-attributes for ref
perfect!
interesting to see astro using import attributes already
thx for the help @Walshy | Deploying
yup
@James are you using the experimental astro:env feature?
And does your project work after deployment? In my case it throughs an error 500.
My project works fine after this
No I don’t use any env feature
Just put the env through cloudflare dashboard
Working perfectly fine after using latest nodejs version
FYI I added
NODE_VERSION = 20
to Wrangler and it still failed. But when I did 21
it continued and only failed later when it said my worker is bigger than 1MiB in size 😅