简体   繁体   English

解析错误:找不到用于 Sanity 的模块“@babel/preset-env”

[英]Parsing Error: Cannot find module '@babel/preset-env' for Sanity

For a React project, I installed Sanity under the schema folder and then I started adding different JS files into it, but even though there is no code in them, I get the error in the header for each js file.对于 React 项目,我在 schema 文件夹下安装了 Sanity,然后我开始向其中添加不同的 JS 文件,但即使它们中没有代码,我也会在每个 js 文件的 header 中收到错误。

I also tried我也试过

npm install --save-dev @babel/preset-react

but it didn't work.但它没有用。

在此处输入图像描述

I started to watch Clever Programmer's Uniswap video but I cannot move forward with the error.我开始观看 Clever Programmer 的 Uniswap 视频,但我无法继续执行错误。

In your Sanity folder, you can add this code to the.eslintrc file:在您的 Sanity 文件夹中,您可以将此代码添加到 .eslintrc 文件中:

"eslint.workingDirectories": ["./web", "./studio"]

So it should be like this:所以它应该是这样的:

{
  "extends": "@sanity/eslint-config-studio",
  "eslint.workingDirectories": ["./web", "./studio"]
}

I don't know if you solved it.不知道你解决了没You might need to change your webpack.config file.您可能需要更改 webpack.config 文件。 Go to: Go 至:

node_modules/react-scripts/config

and open your webpack.config.js .并打开您的webpack.config.js Inside this file search for babel options and add this preset:在此文件中搜索 babel 选项并添加此预设:

presets: [
  [
    require.resolve('babel-preset-react-app'),
    {
      runtime: hasJsxRuntime ? 'automatic' : 'classic',
    },
  ],
],

so your webpack.config file should look like所以你的 webpack.config 文件应该是这样的

test: /\.(js|mjs|jsx|ts|tsx)$/,
include: paths.appSrc,
loader: require.resolve('babel-loader'),
options: {
customize: require.resolve(
  'babel-preset-react-app/webpack-overrides'
),
presets: [
  [
    require.resolve('babel-preset-react-app'),
    {
      runtime: hasJsxRuntime ? 'automatic' : 'classic',
    },
  ],
],
// @remove-on-eject-begin
babelrc: false,
configFile: false,

You can just change your.eslinc files into:您可以将您的 .eslinc 文件更改为:

["next/babel", "next/core-web-vitals"]

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

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