SyntaxError: unknown: 'with' in strict mode
See original GitHub issueBug Report
- I would like to work on a fix!
Current behavior
SyntaxError: unknown: ‘with’ in strict mode (1:27)
Input Code
const babel = require('@babel/core');
var code = 'function f(foo, values) { with (foo) { } }'
var res = babel.transform(code, {
retainLines: true,
compact: false,
presets: ['@babel/preset-env'],
plugins: [
["@babel/plugin-transform-modules-commonjs", { "strictMode": false }]
]
}).code;
Expected behavior
The instrumentation should succeed.
Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)
- Filename:
babel.config.js
None
Environment
None
- Babel version(s): 7.0.0
- Node/npm version: 15.2.0
- OS: [e.g. OSX 10.13.4, Windows 10]
- Monorepo: No
- How you are using Babel: I used the above code
Possible Solution
Additional context
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
SyntaxError: unknown: interface is a reserved word in strict ...
SyntaxError : unknown: interface is a reserved word in strict mode. Is this expected behaviour? How can I get this to compile? I...
Read more >Strict mode - JavaScript - MDN Web Docs
Strict mode makes with a syntax error, so there's no chance for a name in a with to refer to an unknown location...
Read more >JavaScript Mistakes — Strict Mode | by John Au-Yeung
Strict mode eliminates lots of silent errors by changing them to throw ... SyntaxError: Unexpected eval or arguments in strict mode' when we ......
Read more >Strict mode
Strict mode makes with a syntax error, so there's no chance for a name in a with to refer to an unknown location...
Read more >Strict mode - Angular
Enables strict mode in TypeScript, as well as other strictness flags recommended by the TypeScript team. · Turns on strict Angular compiler flags...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think you meant:
You could use
sourceType: "unambiguous"
, which means "if there areimport/export
it’ssourceType: "module"
, otherwise it’ssourceType: "script"
. This does solve the problem perfectly. Thanks a lot!Well, if you are using
import
orexport
it’s going to crash, because they are only allowed in modules.You could use
sourceType: "unambiguous"
, which means "if there areimport
/export
it’ssourceType: "unambiguous"
, otherwise it’ssourceType: "module"
.I think that this will work in 99.9% of the cases (there are some differences between modules and scripts, but usually the problem is only when going from
script
tomodule
).