Module parse failed: 'import' and 'export' may appear only with 'sourceType: module'
时间: 2023-12-26 11:03:33 浏览: 416
Module parse failed: Unexpected token
5星 · 资源好评率100%
This error occurs because the code is using the import and export statements, which are only allowed in modules. To fix this error, you need to add the "sourceType: module" option to your parser configuration. Here's an example of how to do this with Babel:
```
{
"presets": [
["@babel/preset-env", {
"targets": {
"node": "current"
}
}]
],
"parserOpts": {
"sourceType": "module"
}
}
```
In this example, we're using the @babel/preset-env preset to target the current version of Node.js. We've also added the "sourceType: module" option to the parserOpts configuration to enable the use of import and export statements.
阅读全文