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

Use Javascript to deactivate the mouse cursor and rely solely on the keyboard cursor for navigation

I am facing an issue with a div that contains a textarea. The cursor is automatically positioned at the beginning of the text within the textarea. I would like to disable the mouse cursor when hovering over the textarea but still be able to navigate within ...

Saving functions in the localStorage API of HTML5: A step-by-step guide

I have encountered an issue while trying to store an array in local storage using JSON.stringify. The array contains functions (referred to as promises) within an object, but it seems that when I convert the array to a string, the functions are removed. Su ...

Is there a way I can replicate this expandable div?

I have successfully implemented a script that expands and collapses. However, I am facing an issue when trying to use two of these scripts on the same page. I attempted to simply add "_two" to all instances of "accordion," but it doesn't seem to be f ...

How can one properly execute a DELETE request in the NextJS 13.4 API using the latest App Router with Response, NextAPIResponse, and NextResponse?

How can a simple DELETE be properly executed in NextJS 13.4 using the new App Router? The traditional method of performing a delete operation involved utilizing NextAPIRequest, NextAPIResponse, checking for the 'DELETE' method with if (req.metho ...

The test does not pass when attempting to use a shorthand operator to ascertain the truthfulness of

I've encountered an interesting issue with my unit test. It seems to work perfectly fine when I directly return true or false, but fails when I try to use a shorthand method to determine the result. Let's say I have a function called isMatched w ...

Obtain the token by utilizing useReducer in combination with useContext and observe the undefined scenario, part

Yes, I am aware this is my part 2 issue. You can refer to the first part in this question. In the previous part, the problem of getting 'undefined' was resolved but now instead I am receiving an empty object when I log `stateAuth.auth`. Any assis ...

Ways to showcase every resource from an API in React JS

I need help with adding code to display products along with their images from an API in my existing code. Can someone assist me with this? import React, {useState, useEffect} from 'react' import "bootstrap/dist/css/bootstrap.min.css" im ...

What could be causing an issue with CORS in ExpressJS in one scenario but not in another?

I am currently in the process of setting up a database and connecting it to various routes. Interestingly, I have been successful with one route ('register') but encountering issues with another ('login'). Whenever I attempt to run the ...

What could be causing Next.js middleware to run repeatedly?

Recently, I set up a brand new Next.js project using npx create-next-app@latest --typescript. Upon completing the installation (version 13.3.4), without making any modifications to existing files, I introduced a new file named middleware.ts within the src ...

Exploring the concepts of AngularJS directives and resources

I've been experimenting with angularjs and rest service calls to display specific data sets, but I'm encountering challenges with custom directives and resources. Currently, I have a custom directive that loads a list of comments in an applicati ...

Can you help me figure out how to retrieve the index of a CSS element during a 'click' event?

I have a collection of images all tagged with the class thumb. When a user clicks on one of these images, I need to determine which image was clicked within the array of thumbs. Essentially, I am looking for the index of the clicked image within the thumbs ...

Initialize React Native project

Which ruby command shows the path to Ruby: /Users/User/.rbenv/shims/ruby Ruby -v command displays the version of Ruby installed: ruby 2.7.5p203 (2021-11-24 revision f69aeb8314) [x86_64-darwin21] Which bundle command reveals the path to Bundler: /Users/Us ...

Dealing with a jQuery/Javascript/AJAX response: sending a string instead of an integer as a parameter to a

Trying to figure out how to handle passing integers as strings in JavaScript within an AJAX response. Here is the code snippet: message+="<td class='yellow' onclick='open_flag("+i+j+")'>"; The message variable is eventually inse ...

Karma Test Requirement: make sure to incorporate either "BrowserAnimationsModule" or "NoopAnimationsModule" when using the synthetic property @transitionMessages within your application

TEST FILE import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { BrowserAnimationsModule } from '@angular/platform- browser/animations'; import { ManagePageComponent } from './manage-page.component& ...

Adding data from a database into an object in PHP for temporary use during the loading process can be achieved by following

I'm a beginner in PHP and I have some code that retrieves category type data from a database. I want to temporarily store this data in a PHP object while the page is loading. Initially, I need to load all predefined data and then use it when a certain ...

PHP not receiving POST information from $.ajax call

My JavaScript triggers a POST method when the datepicker loses focus, calling the script rent-fetch-pick-up-point.php. However, the PHP script gets stuck at the if-statement because it's not receiving the POST data. The datepicker is associated with a ...

Transmit the identifier of the span tag to the URL seamlessly without the need to refresh

<div id="unique50">Greetings</div> Transfer the code 50 to the designated link by clicking on the specific div element without requiring a page reload ...

Modify the text highlighted in bold within the AngularJS application

In my angular.js application, I have a table that displays elements. The name of these elements sometimes needs to be displayed in bold by adding <b> and </b> tags. However, instead of rendering the name as HTML code, it is showing up as a stri ...

The connections of directives

In my Angular application, I am encountering an issue while trying to enhance the functionality of a third-party directive with my own custom directive. The problem lies in the order of instantiation of these directives. The intended usage of the directiv ...

replace the tsconfig.json file with the one provided in the package

While working on my React app and installing a third-party package using TypeScript, I encountered an error message that said: Class constructor Name cannot be invoked without 'new' I attempted to declare a variable with 'new', but tha ...