I encountered the following error: Failed to parse due to the module '@babel/preset-react' being missing

Encountering a parsing error: Module '@babel/preset-react' cannot be found. Upon creating schema.js, tweetSchema.js, userSchema.js, issues arose with import, export, and export from all three files showing red lines.

schema.js:

import createSchema from 'part:@sanity/base/schema-creator'
import schemaTypes from 'all:part:@sanity/base/schema-type'

import {userSchema} from './userSchema'
import {tweetSchema} from './tweetSchema'

export default createSchema({
 name: 'default',
 types: schemaTypes.concat([userSchema, tweetSchema]),
})

tweetSchema.js:

export const tweetSchema = {
 name: 'tweets',
 type: 'document',
 title: 'Tweets',
 fields: [
  {
   name: 'tweet',
   type: 'string',
   title: 'Tweet',
  },
 ],
}

userSchema.js:

export const userSchema = {
 name: 'users',
 type: 'document',
 title: 'Users',
 fields: [
  {
   name: 'coverImage',
   type: 'string',
   title: 'Cover Image',
  },
  {
   name: 'tweets',
   title: 'Tweets',
   type: 'array',
   of: [
    {
     type: 'reference',
     to: [{type: 'tweets'}],
    },
   ],
  },
 ],
}

Shown below is my package.json file:

{
 "name": "twiiter-clone",
 "private": true,
 "version": "1.0.0",
 "main": "package.json",
 "license": "UNLICENSED",
 "scripts": {
  "dev": "sanity dev",
  "start": "sanity start",
  "build": "sanity build",
  "deploy": "sanity deploy",
  "deploy-graphql": "sanity graphql deploy"
 },
 "keywords": ["sanity"],
 ...
 

tsconfig.json:

{
 "compilerOptions": {
  "target": "ES2017",
  "lib": ["dom", "dom.iterable", "esnext"],
...
 "

Attempts were made to install @babel/preset-react, unfortunately without success.

Answer №1

It's possible that the problem stems from a linter issue. Have you tried opening your project folder directly in your file editor, rather than within a parent folder? I've encountered similar issues before when opening Next.js projects in this way. Give opening your project folder directly a try.

Answer №2

According to @Jelmer, the issue might arise from having multiple folders open within the same workspace.

To resolve this, consider separating the linter if you are working with multiple folders simultaneously (such as a backend and frontend) in the workspace settings (.vscode/settings.json):

{ "eslint.workingDirectories": ["frontend", "backend"] }

Find out more here

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

NPM - Include in package.json without installation

Can a command be executed to validate that the package is a legitimate npm package, include it as a dependency in package.json, but refrain from actually installing it? This question arises from the need to utilize a specific package globally and incorpor ...

What is the process for securing a photo to a canvas?

I have included <input type='file' id="image"> in my HTML code. How can I display the uploaded image on my canvas using p5.js? What is the best way to add an event listener to this action and transfer the uploaded file onto the ca ...

Displaying a MySQL blob image in an HTML file with Vue.js: A step-by-step guide

Here is a Vue file that I have: export default { data(){ return{ info: { name: '', image: '', }, errors: [] } }, created: function(){ thi ...

What is the role of the .connect() method in Web Audio nodes?

Following the instructions found here, which is essentially a copy and paste from this I think I've managed to grasp most of it, except for all the node.connect()'s As far as I can tell, this code sequence is necessary to supply the audio anal ...

Using Javascript to parse SOAP responses

Currently, I am working on a Meteor application that requires data consumption from both REST and SOAP APIs. The SOAP service is accessed using the soap package, which functions properly. However, I am facing challenges with the format of the returned data ...

When the page is refreshed, the Material UI style vanishes

I have decided to transition my React app into a Next.js app in order to benefit from server-side rendering (SSR). Currently, I am utilizing Material UI 4 for styling purposes. After following the documentation provided by Material UI and implementing the ...

Displaying a loading spinner using JQuery while content is being loaded into a div

I have a navigation bar with links that load content from corresponding HTML pages into a div next to the navigation bar when clicked. To make it more user-friendly, I want to display a spinner while the content is loading. However, the current code I trie ...

Get a list of images by incorporating NextJs and Strapi to create a dynamic slider feature

[] I need help creating a slider as I am encountering an error when trying to output an array of objects. The error can be seen here: . Can someone assist me in resolving this issue? Thank you. Here is a screenshot from the admin panel: 1 Below is the c ...

Enhance functionality in JavaScript by accessing the return value from a function

I'm trying to achieve the same outcome using a different method. The first approach is functioning correctly, but the second one is not: <script> function hello(){ var number = document.getElementById("omg").innerHTML; if(numbe ...

Dividing a JSON array by a specific key using lodash underscore

I'm on a quest to extract the distinct items in every column of a JSON array. Here is what I aim to convert : var items = [ {"name": "Type 1","id": 13}, {"name": "Type 2","id": 14}, {"name": "Type 3","id": 14}, {"name": "Type 3","id": 13}, {"na ...

Fixed Navigation - Employing stickUp.js extension

* { box-sizing: border-box; } body { margin: 0; padding: 0; font-weight: 500; font-family: 'Helvetica Neue', sans-serif; } main {} .bckgrnd { background-position: center center; background-repeat: no-repeat; background-attachment: ...

Using HTML, CSS, and jQuery to create a master-detail feature

I'm looking to implement a master-detail layout, so I decided to follow this tutorial for guidance: While trying to replicate the tutorial, I encountered an issue with my code. Here's the code snippet that I am working on: HTML/jQuery <!DO ...

Updating field based on dropdown value in CakePHP 3.6.11

I have the following tables: customers[id, name, surname, phone, text, balance, created] service_types[id, title, price, length, is_subscription, created] customer_service_types[id, customer_id, service_type_id, price, created] Within the add.ctp file o ...

Create a separate server session specifically for handling an ajax request?

Currently, I am working with a collection of PHP server-side scripts that manage user session state by utilizing PHP sessions extensively for authenticated users. For the client side within a mobile application and using Jquery ajax, I am striving to esta ...

Is there a way to automatically update the state in ReactJS whenever new information is added or deleted, without the need to manually refresh the page

I have encountered an issue that I have been trying to resolve on my own without success. It seems that the problem lies in not updating the Lists New state after pushing or deleting from the API. How can I rectify this so that manual page refreshing is no ...

how can you activate a modal without relying on bootstrap?

Could anyone suggest a more efficient way to create a pop-up modal triggered by a button click without relying on bootstrap? I've attempted different methods but haven't achieved the desired result. Here's a sample plunker for reference. Any ...

Practicing diligently, JavaScript code snippets

In my app using Playframework 2.2, I heavily rely on ajax to load content dynamically. There are times when I need to bind or change an event handler after loading content via ajax. For example, if I want to modify the click handler for a newly retrieved ...

Incorporating a .json file into res.render to pass data

Is there a way to pass an object array similar to the one below into res.render? var DataArray = [ {"type": "c#", "script":"csharp script"}, {"type": "javascript", "script":"javascr ...

What is the best way to eliminate .js chunks from a Nextjs application?

I've been working on my Next.js application and recently Lighthouse has been flagging unused chunks. I've come across some mysterious chunk files like ...chunks/26c47f1....6971807....js and ...chunks/25.91c4046....js in my project that are taking ...

Having trouble with VueJS ref not preventing the default form action on submit?

Within my <script> tag, I currently have the following code: render(createElement) { return createElement("form", {ref: "formEl" , on: {submit: this.handleSubmit} }, [ <insert create form inputs here> ]); } handleSubmit(e) { ...