Uncaught SyntaxError: Cannot use import statement outside a module With Worker Function and Fauna DB

I’ m following this tutorial https://developers.cloudflare.com/workers/tutorials/store-data-with-fauna to connect Worker function with Fauna dabase. The problem is that this is not working with
type="javascript"

This is error

Uncaught SyntaxError: Cannot use import statement outside a module
at line 1
[API code: 10021]

If I change it to the

type="webpack"

it’s working, but I really need to be plain javascript… Can anyone confirm me is this even possible to work with type=javascript and to import npm modules in index.js?

The tutorial you linked uses dependencies. Workers are single JS files so to use dependencies they need to be bundled up. That’s why the webpack one works.

Is there any reason you can’t use the webpack one? It’s still the same Worker just it’s using the webpack tool to bundle up.

You can also do the bundling yourself with something like esbuild with esbuild <your-entry-file> --bundle --outdir=dist

Either way, as mentioned, you will need to bundle the dependencies up. This is normal.

Thank you for the response. Yes I need to use javascript because of few reasons and the one is that Fastspring cannot establish secure connection with Worker function which uses webpack.
So just to confirm there is no possibility at all to use javascript even if it’s said in tutorial to use it?

Hey, using a tool like webpack (again, it’s a tool not a language or anything) will not affect a connection or anything.

Webpack is simply bundling the files up. So, moving all the dependencies and your code into 1 single file (so that it can be uploaded). Webpack only has effect over the build process.

In the end (after build) your code is all still JS and will function as you expect. The insecure issue will be unrelated and if you can provide more info, we can help support there.

Well if I try to call that webpack Worker function from fastspring as webhook, I have error HANDSHAKE _FAILURE in Fastspring, I checked the TLS version they both using 1.2 and they have at least one chipper suite that worker and fastspring support… If I try to call simple worker with javascript type it works perfectly…

I already posted the question if you can take a look I would appreciate

P.S What I noticed is when I use webpack and publish that function if I go to quick edit code is unreadable