-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Support sloppy mode #3119
Comments
bun loads code all code in strict mode by default, which is intentional (es modules define this as spec, and node esm does this too). strict mode doesn't allow a number of things like undeclared variables. I wonder if there's a nice way we can enable sloppy mode. |
Probably the better fix here is to detect usages of sloppy mode features and build as CommonJS in that case |
It seems that the usual way of declaring that you want to use strict mode is adding "use strict"; to the beginning of a script or a function. https://www.w3schools.com/js/js_strict.asp I've checked that node.js supports this! |
I kinda like the idea that strict mode is opt out and not opt in because it helps building more modern projects. |
This has since been implemented To enable sloppy mode, use CommonJS in your module and don't include We're unlikely to change this at this stage tbh |
What version of Bun is running?
0.6.6
What platform is your computer?
Linux 5.15.0-40-generic x86_64 x86_64
What steps can reproduce the bug?
Run the following test.js program
What is the expected behavior?
In node.js (version 16.20.0) the output is
2
What do you see instead?
In bun version 0.6.5 this gives an error
ReferenceError: Can't find variable: a
Additional information
While perhaps the current Bun behavior could help writing better code, this is clearly an incompatibility with node that could potentially break a lot of existing code.
I would suggest an option like "bun --declare-vars test.js" (or in a config file) in case that declaring all the variables with let is required.
The text was updated successfully, but these errors were encountered: