Fix Wrangler Require is Not Defined Error
Adjust your Wrangler config file to fix the require is not defined and other uncaught reference errors.
Wrangler is a CLI tool built for Cloudflare Worker developers. You can use Wrangler to create and test Workers in your primary development environment, significantly increasing your efficiency and productivity. If you’re running into some issues with your Javascript markup, this guide may help you out.
Uncaught Reference Error: Require is Not Defined Wrangler Fix
To fix the “require is not defined” error, modify the type attribute in your wrangler.toml file.
- Open the wrangler.toml file in the root of your project
- Find the type = “javascript” line
- Replace it with type = “webpack”
- Run wrangler dev, wrangler preview, or wrangler publish
That should be all there is to it. If you ran into this issue, you are likely running Wrangler version 1. Wrangler 2 plans to omit the type attribute, which will no longer be necessary. You can check the instructions here to get more information on potential code changes you may need to make when upgrading to version 2.
Check out the official compare list to more clearly see the differences between Wrangler 1 and 2. [INFO]
Switching the type to webpack could fix a ton of different errors related to your markup. On the first run after changing the property, you may have to wait for the extra dependencies to complete the installation.
Does Wrangler Support Webpack?
Wrangler version 1 supports webpack via the type and webpack_config attributes through the wrangler.toml file. Wrangler version 2 will remove both the type and webpack_config properties but will still natively support webpack.
Important Wrangler Commands
Here are a few Wrangler CLI commands that you will likely be using regularly:
- wrangler init – Create a wrangler project
- wrangler dev – Launch the development environment
- wrangler publish – Publish your worker to Cloudflare
- wrangler delete – Delete your worker from Cloudflare
- wrangler deployments – View your last ten deployments.
We hope this guide helped you fix your Wrangler issue. For more helpful coding guides, check out our Javascript Section.