-
Notifications
You must be signed in to change notification settings - Fork 915
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
Optional chaining not working (no, not in the template) #1697
Comments
@sodatea 11088 issue is concerned with in the template, my issue is not in the template (see title and description). The problem looks like it's in vue-loader. Please read and reopen. |
Then you need to provide a reproduction repo. It works for most people. |
A misconfigured |
I suppose most people use Babel and have the Babel plugin and that's why it works for them. I don't want to have to do all that just to get totally valid JavaScript to work. And I also "do not use TypeScript," so it's not a ts config issue. One of the reasons I avoid Babel and TS is to minimize these kinds of time-wasting issues. The error I shared leads me to believe that out-of-the-box whatever Vue CLI (or vue-loader) comes with and its default config does not support optional chaining. Perhaps it's as simple as an internal version bump? |
Here's my package.json if that helps:
|
Vue info as well:
|
It's webpack that can't yet parse such syntax webpack/webpack#11198 |
@sodatea ok, thanks! |
This should be re-opened its not working without typescript |
Optional chaining is only in Webpack v5. Looks like Vue Loader is on v4. When is will Vue Loader move to v5? |
Encountered same error after I changed my Changing
|
I spent several hours on this today and what ultimately worked for me was setting the presets and plugins directly in the webpack rule:
|
Have tried some of the workarounds and none seem to work for my minimal setup. This needs to be reopened and resolved inside Vue Loader itself by updating to Webpack 5, which is required for optional chaining support. @sodatea is there something preventing the upgrade to WP5? |
@jfbrennan Vue Loader has supported webpack 5 for a while. |
Try vue-template-babel-compiler It will enable Github Repo: vue-template-babel-compilerDEMOUsagePlease refer to REAMDE for detail usage Support for |
Idea from @atflick worked for me, I wanted to be very explicit though about module that I couldn't compile and set this in const path = require('path');
module.exports = {
chainWebpack: config => {
config.module
.rule('monaco')
.test({
test: /\.js$/,
// See: I'm pointing to a single folder that had the problem, so that I'm not killing
// babel's caches for other modules
include: path.join(__dirname, 'node_modules/monaco-editor/esm/vs'),
})
.use('babel-loader')
.loader('babel-loader')
.options({
presets: ['@babel/preset-env'],
plugins: ['@babel/plugin-proposal-optional-chaining']
}).end();
}
} |
Great, this has solved my problem, but in my project, after this configuration, an error is reported as follows. I also need to install core js. `These dependencies were not found:
To install them, you can run: npm install --save core-js/modules/es.function.name.js core-js/modules/es.object.to-string.js core-js/modules/es.regexp.exec.js core-js/modules/es.string.iterator.js core-js/modules/es.string.search.js core-js/modules/web.dom-collections.iterator.js` |
I had the same issue and the problem was that babel was not set as the parser.
|
Version
15.9.2
Reproduction link
[Bogus link removed] Seriously, why do you make it so hard to submit a simple issue?????
Steps to reproduce
I am trying to use the optional chaining operator inside one of my methods:
I have the latest versions of Vue (2.6.11) and Vue CLI (4.4.6). My package-lock tells me Vue CLI pulled in vue-loader version 15.9.2. I also use SFC. I do not use TypeScript. I do not have any special Babel config or extra plugins. It makes no sense to me that I can use other modern parts of js, but something is barfing on the optional chaining operator.
What is expected?
My code would compile.
What is actually happening?
My code fails to compile and Vue CLI outputs this error (doesn't like the optional chaining operator):
I am under the impression this should work because 1) this is just vanilla js!!!, 2) Babel, which I think vue-loader is using, supports the optional chaining operator, and 3) it's not in the template which won't be supported until Vue 3.
I tried explicitly adding
@vue/cli-plugin-babel": "^4.4.6"
to my project and that didn't change anything.Please help!
The text was updated successfully, but these errors were encountered: