score:0
To Fix the Issue, We Need to First Understand the Issue.
The error message you received was from the parser. Which output the following:
file.js
1:1 error Parsing error: Octal literal in strict mode
> 39 | language.french.value = ' caract\350res';
When error messages are implemented correctly they are a great resource for sniffing out the root causes of difficult errors. The error message above is not the most verbose error message, but it hits the nail on the head — the message has 2 pertinent pieces of information that should be noted.
Its a
Parsing error
, meaning an error occurred while a parser was parsing the JS file.and, the second is that the error occurred because an
Octal literal
was located in a script that is being ran instrict mode
.
Put it together, and it becomes clear. The parser threw an error because there is an octal being used in a script that is ran in strict mode
.
I think its obvious from the error message, but if you haven't realized it, Octal's are not allowed in strict mode
. With or with out ESLint this is true. Just FYI.
The Problem is Not Strict-Mode — the Problem is the Module-Type
Contemporary ECMAScripts
have implemented something called ES-Modules
, or ESM
. They are Very cool but I am not going to explain what they are further than they are a ECMAS
supported module, something that is relatively new to front-end JS. Node on the other hand has had modules for a long time, how ever Node.js Modules
are not Standard ECMAS JavaScript. With node, you can now create, ESM
modules, or CJS
modules.
Q?
How does any of this have to do with our problem?
A:
Well because 'use strict';
, or Strict Mode
is the ESM standard, and all ES Modules
are parsed in strict mode, and therefore; some of the non-strict constructs, like the octal literal above, will cause parsing errors when ESLint parses modules that are type: ESM
. Modules that are type CJS
, or Common-JS Modules
, often depend on those 'strict-mode illegal constructs` (like the octal literals), and if you depend on them your bundle will blow up. There's nothing we can do about that.
Its important moving forward to configure your ESLint parser to parse the correct type of module:
// Using the babel parser you would do this
// @file ".eslintrc(.?)"
{
"parser": "@babel/eslint-parser",
"parserOptions": {
"sourceType": "script"
}
}
The module types are often defined as Scripts
or Modules
, this is because as far as ECMAS is concerned, a JavaScript file is either a Standard JS Script, or a ESM Module
. You should also configure your package.json file if your using one.
// @file "package.json"
{
type: module /* or script */
}
score:2
I've just run into the same issue, finally found an answer on github.
You can turn off the global strict mode by changing the sourceType
to script
within your .eslintrc file:
{
...
parser: 'babel-eslint',
parserOptions: {
sourceType: 'script'
}
...
}
Or, if you want to set this through the cli then simply:
eslint --no-eslintrc --parser=babel-eslint --parser-options=sourceType:script file.js
Source: stackoverflow.com
Related Query
- Eslint disable strict mode when using babel parser
- How to disable strict mode while bundling React using webpack
- Should not have to disable eslint when using with react
- error: Unexpected strict mode reserved word when using react
- How to set React to production mode when using Gulp
- react-hook-form: Validation not working when using onBlur mode
- Babel 6 react JSX transformer - disable strict
- Is a good convention using semicolon at the end of the line when using ES6 in babel
- Warning: Using UNSAFE_componentWillMount in strict mode is not recommended (upgrade to CRA 4.0.2)
- Request header not set as expected when using 'no-cors' mode with fetch API
- Disable does not work for checkbox when using this.props
- Support for the experimental syntax 'jsx' isn't currently enabled when using webpack and babel
- How to output eslint errors in the browser when using reactjs
- You should disable react-transform-hmr in production by using `env` section in Babel configuration
- Typescript and eslint issue when using styled-components and Material UI: `React does not recognize the `showText` prop on a DOM element`
- Warning messaged from ESLint when using React Hooks
- Fix ESLint warnings in next.js's _document.tsx thrown by Document<any> and ctx.renderPage = () when using TypeScript
- How to disable eslint check on development mode in reactjs
- Next.js - Disable jump to anchor when using router.push()
- eslint strange error when using redux
- How to temporarily turn on/off React development mode when using webpack?
- React code is not running when using Webpack, React, Babel combination
- What is the correct way to initiate a side-effect on page load when using React Strict Mode?
- Uncaught SyntaxError: Unexpected token '<' When using create-react-app develop mode
- Eslint error when using the for in loop how to restructure
- Getting this error when using Babel and Webpack on React DnD project
- conditionally disable an option using react select not work when change option props passed to the Select
- Is there a way to disable apollo-link-dedup when using apollo useQuery?
- How to deploy Node.js / React application to Heroku using Babel when writing ES6 code?
- using update immutablity helper I get eslint error : Use callback in setState when referencing the previous state
More Query from same tag
- AnimatePresence not working with clipPath inset
- How to get and manage language from the path in URL in react-admin
- React: duplicated item in list
- Can I use two useEffect and have map inside a map
- React child receive old state props, NOT updated state props
- Using rsuite to draw a table in react
- wp-json API returns 401 on post edit with React and nonce
- Bootstrap Reactstrap Collapse is not working with list of components
- ReactJS ApexChart problem with displaying the correct xlabel
- How can I store previous values instead of storing the value in array of objects in react state
- Syntactical error/jshint with in-line & map in ReactJS
- Location Proxy with npm serve
- what is the alternative of the code below in react from vue js
- Can a component internally assign a ref to one of it's children?
- Detect update in observable prop
- Set state to new object using previous state with matching values
- Nexus & GraphQL: Root typing path for the type "context" does not exist
- Formatting a hook array from different inputs in a form
- Material Mui . Remove padding from grid item
- How to create a styled-component library package to work with Gatsby
- ES6: .reduce function
- How to dynamically add data to a table via map/if or terinary operator in JSX
- How to fetch data before render functionnal component in react js
- React - Logout component issue
- Performance when dealing with large matrices in React
- Mapping through elements in array and displaying them in a paragraph
- How can I show image passed as this.state in React.js?
- Package typewriter-effect changeDelay method doesn't work
- How to detect long touch in javascript in mobile devices without jQuery
- validation fails on submit