react-scripts@2.0.0-next.3e165448 - ReferenceError: require is not defined :: due to graphql using .mjs
See original GitHub issueIs this a bug report?
Yes.
The latest react-scripts@2.0.0-next.3e165448
with Webpack 4 support breaks when bundling dependencies (node_modules
) with .mjs
files, such as graphql
.
Did you try recovering your dependencies?
Yes.
Which terms did you search for in User Guide?
In the User Guide, Issues and PRs I searched for:
ReferenceError: require is not defined
graphql
mjs
Environment
Environment:
OS: macOS Sierra 10.12.6
Node: 8.9.4
Yarn: 1.7.0
npm: 5.6.0
Watchman: 4.1.0
Xcode: Xcode 9.2 Build version 9C40b
Android Studio: 2.1 AI-143.3101438
Packages: (wanted => installed)
react: ^16.4.1 => 16.4.1
react-dom: ^16.4.1 => 16.4.1
react-scripts: ^2.0.0-next.3e165448 => 2.0.0-next.3e165448
Steps to Reproduce
(Write your steps here:)
npx create-react-app my-app && cd my-app
npm install
npm install graphql react-scripts@2.0.0-next.3e165448 --save
- Add [graphqlCode] after
import "./App.css"
insrc/App.js
npm start
[graphqlCode]
import {
graphql,
GraphQLSchema,
GraphQLObjectType,
GraphQLString
} from "graphql";
var schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: "RootQueryType",
fields: {
hello: {
type: GraphQLString,
resolve() {
return "world";
}
}
}
})
});
Expected Behavior
Actual Behavior
Reproducible Demo
https://github.com/christemple/create-react-app-graphql-issue
git clone git@github.com:christemple/create-react-app-graphql-issue.git
npm install
npm start
Additional
I noticed this when trying to install the AWS Amplify package, which I noticed has a dependency on graphql
.
I’m happy to raise a PR for a fix, I just wanted to get verification that it’s a needed fix before doing so.
Thanks
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Client on Node.js: Uncaught ReferenceError: require is not ...
throws the Uncaught ReferenceError: require is not defined. I was able to work around that by specifying Node.js integration as true when ...
Read more >Getting Started With GraphQL.js
To handle GraphQL queries, we need a schema that defines the Query type, and we need an API root with a function called...
Read more >API Reference: ApolloServer - Apollo GraphQL Docs
This article documents the ApolloServer class from the @apollo/server package. You can use the ApolloServer class to create an instance of Apollo Server ......
Read more >TypeGraphQL · Modern framework for GraphQL API in Node.js
This allows you to define both the GraphQL type and the entity in a single class - no need to jump between multiple...
Read more >graphql-request - npm
import { request, GraphQLClient } from 'graphql-request' // Run GraphQL queries/mutations using a static function request(endpoint, query, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The following in the webpack config, just before the file loader, appears to solve the issue:
I can do more testing and get a root cause and solution along with a PR up this evening
Because my api uses different babel versions, I had
react-scripts
in the monorepo’snohoist
declaration. I was then able to resolve this by adding further libs to thenohoist
declaration: