简体   繁体   English

SyntaxError: JSON5: 无效字符 'm' 在 3:1

[英]SyntaxError: JSON5: invalid character 'm' at 3:1

Babel is giving me the following error: Babel 给我以下错误:

../../node_modules/next/dist/pages/_error.js
SyntaxError: JSON5: invalid character 'm' at 3:1

My .babelrc and babel.config.cjs :我的.babelrcbabel.config.cjs

/* eslint-disable no-template-curly-in-string */

module.exports = {
  presets: [['next/babel']],
  plugins: [
    [
      'babel-plugin-transform-imports',
      {
        lodash: {
          transform: 'lodash/${member}',
          preventFullImport: true,
        },
        '@mui/material': {
          transform: '@mui/material/${member}',
          preventFullImport: true,
        },
        '@mui/icons-material': {
          transform: '@mui/icons-material/${member}',
          preventFullImport: true,
        },
        '@mui/lab': {
          transform: '@mui/lab/${member}',
          preventFullImport: true,
        },
<snip>

Per the babel Config Files documentation :根据babel配置文件文档

.babelrc is an alias for .babelrc.json .babelrc.babelrc.json的别名

and

babel.config.json and .babelrc.json are parsed as JSON5 and should contain an object... babel.config.json.babelrc.json被解析为 JSON5 并且应该包含一个对象......

The error message you are getting confirms this: Babel is parsing the file as JSON5 and beginning on line 3 column 1 the content is not valid JSON5.您收到的错误消息证实了这一点:Babel 正在将文件解析为 JSON5,并且从第 3 行第 1 列开始,内容不是有效的 JSON5。 If you remove the module.exports = from that line, the error will be fixed.如果从该行中删除module.exports = ,错误将得到修复。

(I cannot tell whether you have other errors in you .babelrc since you didn't not present the entire file. Once you fix the above line you'll find out.) (我无法判断你的.babelrc中是否还有其他错误,因为你没有提供整个文件。一旦你修复了上面的行,你就会发现。)

On the other hand, your file babel.config.cjs is expected to be valid Javascript, you would need to retain the module.exports = .另一方面,您的文件babel.config.cjs应该是有效的 Javascript,您需要保留module.exports = Or you could rename it to babel.config.json and use the same format as your .babelrc .或者您可以将其重命名为babel.config.json并使用与您的.babelrc相同的格式。

You may also want to rename your .babelrc to .babelrc.json to make its format explicit in its name.您可能还想将.babelrc重命名为.babelrc.json以使其名称中的格式明确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM