The project cannot recognize the ?. syntax, resulting in an error Module parse failed: Unexpected token

1. The first case is if you need to import the source code of the component library, for example, if you want to import a packaged component:

First find the place to report this problem

insert image description here
I am here because of es grammar problems.
insert image description here
If you also installed a package with npm, and then reported this grammar error when importing, then you can continue to read down. If not, you don’t need to read down.

Cause of the problem:
Because the imported component library is directly uploaded to the source code, webpack must be informed that the library needs to be compiled to convert the features of es6 and es7 in the source code to es5

Solution:
1. Add transpileDependencies: ['/@yabby-business/'] in vue.config.js 2. There is another way to specify the code used when importing the library in babel.config.js is esbuild
insert image description here

insert image description here

2. The second case is that all ?. grammars in the project have model parse problems:

There is a high probability of this situation because the vue-loader version of the project is higher than 15+ , and this problem will occur. You can check your own vue-loader version in node_modules . If it is 15+ version, try to install vue-loader first. Version drops below 15

npm i vue-loader@14.1.1

After down, try npm run again

1. If it still doesn’t work, someone or you deleted the package-lock of the project , and then re-npm install the problem.
2. In this case, it is recommended to find the package-lock of the previous history of
this project 3. Or go to another project with a vue-loader version below 15 and copy a package-lock to this project
4. Then delete the node_modules of this project
5. Re-npm install, it will be fine

Guess you like

Origin blog.csdn.net/weixin_45717984/article/details/125005282