Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

graphql import broken in Next.js since v2.1.0-alpha.1 #1591

Closed
jaydenseric opened this issue Jan 29, 2018 · 15 comments
Closed

graphql import broken in Next.js since v2.1.0-alpha.1 #1591

jaydenseric opened this issue Jan 29, 2018 · 15 comments

Comments

@jaydenseric
Copy link
Contributor

jaydenseric commented Jan 29, 2018

Importing graphql in a component in a Next.js project works in v2.1.0-alpha.0 but causes errors for all newer alpha and beta versions.

import { graphql } from 'react-apollo'

screen shot 2018-01-29 at 8 25 44 pm

I'm unsure if this is special to Next.js or if it is simply an issue for all Webpack users.

@jaydenseric
Copy link
Contributor Author

Potentially related? #1590

@chutiphon-k
Copy link

ME TOO

@binkpitch
Copy link

binkpitch commented Jan 30, 2018

I got this too.

@edorivai
Copy link
Contributor

edorivai commented Jan 30, 2018

This is not Next.js specific.

Running the following in node also fails:

const apollo = require('react-apollo');

console.log(apollo.graphql); // logs "undefined"

I've got this happening in [email protected] btw

@petetnt
Copy link
Contributor

petetnt commented Jan 30, 2018

Pretty sure this was borked in #1576 / 18939c2

@vjpr
Copy link

vjpr commented Jan 30, 2018

next.js transpilation:

var _reactApollo = require('react-apollo');
(0, _reactApollo) // {default: ..., renderToStringWithData: ...}
// Missing graphql export.

react-apollo/index.js

"use strict";
function __export(m) {
    for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./browser"));
var renderToStringWithData_1 = require("./renderToStringWithData");
exports.renderToStringWithData = renderToStringWithData_1.renderToStringWithData;
//# sourceMappingURL=index.js.map

react-apollo/index.mjs

export * from './browser';
export { renderToStringWithData } from './renderToStringWithData';

package.json

...
"main": "react-apollo.umd.js"
"module": "index.mjs",
"browser": "react-apollo.browser.umd.js",
...

// fails
import {graphql} from 'react-apollo/index.js'
import {graphql} from 'react-apollo/index'

// fails too (i thought this worked but it doesn't)
import {graphql} from 'react-apollo/index.mjs'

I guess a workaround could be to get Next to choose mjs over js.


Okay so react-apollo/index.js works. But the main entry in pjson is loading the umd.js that is broken.

The workaround is to make it us the index.js. I do this in my .babelrc like so:

Clear your node_modules/.cache and build too.

You need babel-plugin-module-resolver too.

"plugins": [
    [
      "module-resolver",
      {
        "alias": {
          "^react-apollo$": "react-apollo/index"
        }
      }
    ]
  ]

EDIT: Changed from json5 to json format. @pantharshit00

Hopefully its fixed soon though.

@pantharshit00
Copy link

pantharshit00 commented Jan 31, 2018

Thanks for the workaround

Copy and paste ninjas there is a syntax error in the babelrc snippet so paste this snippet instead. Above one has : and " synatx issues

 "plugins": [
    [
      "module-resolver",
      {
        "alias": {
          "^react-apollo$": "react-apollo/index"
        }
      }
    ]
  ]

Thanks again @vjpr

I hope the apollo team get this working soon so that I may eliminate babel plugin in future .

@brandonmp
Copy link

hm. implementing the fix in post above creates all kinds of errors w/ renderToStringWithData.js and react-dom

anyone else hitting this?

error:

ERROR in ./node_modules/react-apollo/renderToStringWithData.js
Module not found: Error: Can't resolve 'react-dom/server' in '/mnt/c/Users/brand/code/admitbrain/node_modules/react-apollo'
 @ ./node_modules/react-apollo/renderToStringWithData.js 3:15-42
 @ ./node_modules/react-apollo/index.js
 @ ./higher-order-components/withApollo.js
 @ ./pages/index.js
 @ multi ./pages/index.js

@pantharshit00
Copy link

@brandonmp @vjpr This is now fixed in next js.

https://github.com/zeit/next.js/releases/tag/5.0.1-canary.2

@danielkcz danielkcz mentioned this issue Mar 15, 2018
@danielkcz
Copy link
Contributor

danielkcz commented Mar 15, 2018

It's somewhat funny looking within a debugger when Webpack (in CRA)

image

@wesbos
Copy link

wesbos commented Mar 28, 2018

I've tried the posted workaround and I still get this error:

Unexpected token export
/......../node_modules/react-apollo/index.js:1
(function (exports, require, module, __filename, __dirname) { export * from './browser';
                                                              ^^^^^^

Anyone have some insight to what is happening?

@pantharshit00
Copy link

@wesbos Hi I am one of your happy customers.

I too got those errors.
From my investigation there is no need of workaround now.

Stable react Apollo is compatible with next.

Your next version should be higher than next 5.0.1-canary2 . That fixes this message. I recommend the newly launched 5.1

And react Apollo version should be 2.1 or higher not any beta version.

This is a new project using both https://github.com/JesseRWeigel/javascript-af

@wesbos
Copy link

wesbos commented Mar 29, 2018

@pantharshit00 thank you - I tried upgrading to Next 5.1 and the error persists :( - so I'm not sure if we had the same errors

@wesbos
Copy link

wesbos commented May 14, 2018

pretty sure this can be closed

@rosskevin
Copy link
Contributor

I'm pretty sure this was solved in July. If not ping me and I'll reopen.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests