-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Netlify adapter: Optional chaining "?." not supported by default in netlify #2687
Comments
A small update: it seems another way to prevent this issue is adding the following to
|
This sounds like the same as - or very similar to - #2679. |
This is similar but slightly different to the CF Worker issue. This is an AWS Lambda runtime error, whereas the CF worker issue is a bundler error as far as I can tell. Netlify functions written in JavaScript are not bundled by default and the default AWS Lambda runtime is node 12 which does not support optional chaining. Typescript projects are automatically bundled with An alternative (or addition) to bundling with Something like the following should work. [build]
# your config
[build.environment]
AWS_LAMBDA_JS_RUNTIME = "nodejs14.x" |
Thanks @pngwn, I can confirm that activating |
I don't like the idea of introducing a second unnecessary bundling step I think setting |
Maybe it makes sense, but in that case, I would put that information front and center in the docs, as the consequences of not doing so and discovering this problem when deploying are really ugly. Especially when node 12 is a relic for today's standards! |
Had this same issue, and like @jsilveira it took me a while to work out what was going on as the error message is quite opaque (this is a Netlify issue). Setting |
Feel free to send a PR to update the docs! |
Per a comment on the PR (#2715 (comment)) from the Netlify team:
|
This reverts commit 47346d9. nvm, going to do this sveltejs/kit#2687 (comment)
* update deps * update server const * add router/hydrate consts * try to set up netlify adapter * remove adapter-static * try prerendering pieces * add netlify.toml * try fixing func issue sveltejs/kit#2687 (comment) * Revert "try fixing func issue" This reverts commit 47346d9. nvm, going to do this sveltejs/kit#2687 (comment) * add netlify local dev command * methinks this will work, just manually copy over stuff * try including files in functions * don't need to copy anymore * use old node compatible replaceAll * disable client side router globally why isn't this working?
just ran into this issue today on netlify. https://app.netlify.com/sites/swyxkit/deploys/61cdec4d0b7920ae2185032e 1:29:28 AM: $ npm run build
1:29:28 AM: > [email protected] build /opt/build/repo
1:29:28 AM: > svelte-kit build
1:29:28 AM: (node:3291) ExperimentalWarning: The ESM module loader is experimental.
1:29:28 AM: file:///opt/build/repo/node_modules/@sveltejs/kit/dist/cli.js:926
1:29:28 AM: https = https || !!vite_config.server?.https;
1:29:28 AM: ^
1:29:28 AM: SyntaxError: Unexpected token '.'
1:29:28 AM: at Loader.moduleStrategy (internal/modules/esm/translators.js:81:18)
1:29:28 AM: npm ERR! code ELIFECYCLE
1:29:28 AM: npm ERR! errno 1
1:29:28 AM: npm ERR! [email protected] build: `svelte-kit build` just leaving here for others to find - gonna try the solution mentioned in #2715 (comment) (set env var in UI because env var in toml doesnt work) |
I tried both solutions:
I tried setting in
I did a "clear cache and deploy". Same problem:
|
@dimavolo I was getting the exact same error your were getting. My previously working site suddenly spewed out that error after updating to latest kit and netlify-adapter. I could recreate it locally using I was able to resolve it by adding...
...to my It looks to me that there is a bug in the CJS version of adapter-netlify which causes a bad code substitution during building which results in some errant code being generated. When using CJS, line 6 of
...which contains the syntax error that leads to the problem we both encountered. The CJS version of
...whereas the ESM version looks like...
The code substitution is based on replacing |
From https://docs.netlify.com/functions/build-with-javascript/?#runtime-settings:
This should be fixed now |
Describe the bug
After successfully deploying a very simple Svelte Kit app (one page, one json endpoint) with netlify adapter, my deploys would succeed but when visiting the deployed production website netlify would fail with error:
Not being able to debug netlify, it took me quite some time of googling to realize this was caused by the optional chaining operator
?.
being used in my code and not being supported by the default Netlify build (and not being transpiled during build).I worked around the issue by adding extra configuration to vite so that the js code was lowered to es6:
I took the default demo svelte kit app, added
?.
, followed https://github.com/sveltejs/kit/tree/master/packages/adapter-netlify steps and deployed and reproduced the error. If others are experiencing this onboarding to svelte kit and netlify adapter It would be important to change the adapter to handle this by default more gracefully or improve documentation? Am I missing something obvious here?Reproduction
Repo reproducing this: https://github.com/jsilveira/bug-sveltekit-optional-chaining-netlify (svelte kit default app modifying
src/routes/todos/index.json.js:8
to use?.
). Deployed in netlify, visit: https://distracted-wozniak-9548a1.netlify.app/todos to see the netlify error in action.System Info
Severity
serious, but I can work around it
The text was updated successfully, but these errors were encountered: