question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

miniflare throws SyntaxError with module format worker configuration but works with wrangler

See original GitHub issue

Hi,

I setup a module format worker using esbuild, and got it working using wrangler. However when I went to setup tests using miniflare the exact same configuration throws an error:

SyntaxError: Unexpected token 'export'

I have been bashing my head against it for a while, but cannot work out what the issue is. I created a minimal test repo to show the issue: https://github.com/autotelic/esm-wrangler-miniflare.git

All help gratefully received!

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
eadmundocommented, Aug 17, 2022

worked perfectly 😄 thanks so much @mrbbot (and also for everything you’ve done in developing miniflare, an amazing tool!)

1reaction
mrbbotcommented, Aug 17, 2022

Hey! 👋 Unlike Wrangler 2, Miniflare isn’t able to auto-detect you’re using a module format worker. You’ll need to add the --modules flag to your miniflare package.json script. Miniflare also doesn’t support the main field in wrangler.toml, but will read your main module from the module field in package.json (like Wrangler 1).

-  "main": "./dist/index.js",
+  "module": "./dist/index.js",
   "scripts": {
     "build": "esbuild --format=esm --bundle --sourcemap --outdir=dist ./src/index.js",
     "wrangler": "wrangler dev",
-    "miniflare": "miniflare"
+    "miniflare": "miniflare --modules"
   },
Read more comments on GitHub >

github_iconTop Results From Across the Web

Conflict in wrangler.toml between miniflare and ... - GitHub
When using esbuild everything works in miniflare just fine, but when ... to Workers Docs field main is supported in modules format (beta...
Read more >
Using the CLI - Miniflare
If you're using an ES module format worker, bindings will be accessible via the env global variable. The REPL can be configured using ......
Read more >
Doubling down on local development with Workers: Miniflare ...
We want all developers to be able to take advantage of the improved local experience, so we're making it easy to start a...
Read more >
Miniflare 2.0: fully-local development and testing for Workers
I wanted a magical simulator that would just work ✨ in existing projects, focusing on the developer experience, and — by the reception...
Read more >
Integrate Remix with Cloudflare Pages - Jacob Paris
Wrangler is the CLI for working with Cloudflare Workers. ... but they use a setup function so that you don't have to import...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found