Skip to content

Add babel-plugin-dynamic-import-node suggestion to README.#35

Closed
ramesaliyev wants to merge 2 commits intojamiebuilds:masterfrom
ramesaliyev:ramesaliyev-babel-plugin-dynamic-import-node
Closed

Add babel-plugin-dynamic-import-node suggestion to README.#35
ramesaliyev wants to merge 2 commits intojamiebuilds:masterfrom
ramesaliyev:ramesaliyev-babel-plugin-dynamic-import-node

Conversation

@ramesaliyev
Copy link

Hello, firstly thanks for making this library and sorry for my english. I had an issue and found a solution but I'm not sure about it. Here is my story;

After using react-loadable with babel-plugin i'm encounter an issue which causes my first renders on server wont serves loadable component. After some digging i realise webpack splits my code into two chunks (one for main and one for loadable) and tries to load loadable component with promise (with load() function in library). And because server dont waits for this loading completed; my first requests always returns null for loadable-component and others work well.

I dont know if this issue is common or just because of my webpack configuration, or because im using babel "syntax-dynamic-import" plugin (etc), but after digging for hours i found solution as using babel-plugin-dynamic-import-node plugin for only my server side webpack (babel actually).

Since issues are disabled i had to open this PR, its okay if you dont accept it. But now it works like a charm! Thanks again :)

README.md Outdated

**Note:**

If you're using babel + webpack with [syntax-dynamic-import](https://babeljs.io/docs/plugins/syntax-dynamic-import/) plugin and it causes your server-side-rendering dont render on the first request. Consider using [babel-plugin-dynamic-import-node](https://github.com/airbnb/babel-plugin-dynamic-import-node) plugin for your server build. It'll convert **import()** to **require()** and ensure synchronous rendering.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'll convert import() to require() and ensure synchronous rendering.

This isn't true, this is the basic transformation:

Input:

import('test-module');

Output:

Promise.resolve().then(() => require('test-module'));

Using this transform by itself will not ensure synchronous rendering. You'll still need to specify serverSideRequirePath or use the react-loadable/babel plugin.

Copy link
Author

@ramesaliyev ramesaliyev Apr 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I'm not saying using "babel-plugin-dynamic-import-node" alone will do the work. I am using babel-plugin-dynamic-import-node with the react-loadable/babel plugin of course.

But without babel-plugin-dynamic-import-node my first server-side-renders always return null for loadable-component as i explain above.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ramesaliyev Do you compile server side code w/ webpack? If yes, then try this in the webpack config for server:

new webpack.optimize.LimitChunkCountPlugin({
  maxChunks: 1,
}),

Copy link

@mshustov mshustov May 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexfedoseev I spent 2 hours, finished with the same solution as you and then found that comment in issues 😄
send PR with comment in Readme #38

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexfedoseev thanks for suggestion, since i havent find chance to test it yet, i'll let you know.

@restrry im glad that you've found solution in these lost streets 😄

@faceyspacey
Copy link

The original plugin should work. It's always worked for me everywhere. Id like to get to the bottom of this. Can U paste some code or perhaps a link to a minimal repo.

Repository owner deleted a comment from faceyspacey Jun 8, 2017
@hhhonzik
Copy link

I have an exactly same problem and i think its caused by babel-plugin-import-inspector implementation.

I have a babel plugin can do 2 things - either use import inspector (and leave import) to give a syntax error, or use babel-transform-dynamic-import-node (or similar) and not load the import-inspector. That results to render null.

  1. import-inspector transpiled with this settings:
const code = require('babel-core').transform("import('mamiko.js');", {
  "plugins": [
    "syntax-dynamic-import",
    [
      "import-inspector",
      {
        "serverSideRequirePath": true
      }
    ]
  ]
});

console.log(code.code);

results in this, which throws a syntax error if i try to run it on node:

import _path from 'path';
import { report as _report } from 'import-inspector';

_report(import('mamiko.js'), {
  currentModuleFileName: 'unknown',
  importedModulePath: 'mamiko.js',
  serverSideRequirePath: _path.join(__dirname, 'mamiko.js')
});
  1. Adding a transform plugin it then transpiles the code like this:
Promise.resolve().then(() => require('mamiko.js'));

This doesn't work on first load, because Promise.resolve() will update the component state after the render() function is processed.

I think the problem is with babel changing order of plugins or maybe can be something else.

@anilanar
Copy link
Contributor

anilanar commented Jul 10, 2017

@hhhonzik @fdubost @ramesaliyev

You get a syntax error because I'm assuming you are not using babel-plugin-syntax-dynamic-import which adds ES6 import syntax to babel.

If you are trying to prevent code splitting, use webpack.optimize.LimitChunkCountPlugin.

So you don't need a transform plugin for import to work.

#54 fixes a bug that causes react-loadable to not render on the first server-side request.

Repository owner deleted a comment from fdubost Jul 11, 2017
@kjs3
Copy link

kjs3 commented Jul 13, 2017

@anilanar, do you have an example project with SSR? I'm facing a similar issue and always getting the loading component in server rendering unless I use babel-plugin-dynamic-import-node. I've tried limiting chunks to 1 but that doesn't seem to make any difference.

Here's the js section of my server webpack config.

{
  test: /\.js$/,
  exclude: /node_modules/,
  use: {
    loader: 'babel-loader',
    options: {
      babelrc: false,
      cacheDirectory: true,
      presets: [
        'env', 
        'react',
      ],
      plugins: [
        ['import-inspector', {
          'serverSideRequirePath': true,
          'webpackRequireWeakId': true,
        }],
        'syntax-dynamic-import',
        'transform-object-rest-spread',
        'transform-runtime',
      ],
    },
  },
}

I've tried different plugin orders but nothing seems to make a difference.

@anilanar
Copy link
Contributor

@kjs3 Are you excluding node_modules from webpack compilation? If so, check this out: https://twitter.com/mostruash/status/884194310769565697

@appigram
Copy link

appigram commented Sep 9, 2017

@thejameskyle @anilanar I have an exactly same problem like @hhhonzik .
Im using Meteor stack. On client-side all works fine, but not on server-side

My full .babelrc file

{
"presets": [
"env",
"react",
"meteor"
],
"plugins": [
["lodash", { "id": ["lodash", "semantic-ui-react"] }],
"transform-runtime",
"syntax-dynamic-import",
"dynamic-import-node",
["import-inspector", {
"serverSideRequirePath": true
}],
"transform-object-rest-spread",
"transform-class-properties",
"transform-react-constant-elements",
"transform-react-inline-elements",
"transform-react-remove-prop-types",
"transform-dead-code-elimination"
]
}

With this config I have loading: true state always
res object is:

{ loading: true,
loaded: null,
error: null,
promise: Promise { }
}

metadata is empty, but should be smth like:

{ currentModuleFileName: 'imports/modules/getDynamicComponent.js',
importedModulePath: '../ui/components/Posts/BestPosts.jsx',
serverSideRequirePath: '/imports/ui/components/Posts/BestPosts.jsx'
}

If I remove dynamic-import-node then I see SyntaxError: Unexpected token import
res object

{ loading: false,
loaded: null,
error: /imports/ui/components/Posts/BestPosts.jsx:1
(function (exports, require, module, __filename, __dirname) { import React from 'react'
^^^^^^
SyntaxError: Unexpected token import
at createScript (vm.js:74:10)
at Object.runInThisContext (vm.js:116:10)
at Module._compile (module.js:537:28)
at Object.Module._extensions..js (module.js:584:10)
at Module.load (module.js:507:32)
at tryModuleLoad (module.js:470:12)
at Function.Module._load (module.js:462:3)
at Module.require (module.js:517:17)
at load (/node_modules/react-loadable/lib/index.js:58:31)
at new LoadableComponent (/node_modules/react-loadable/lib/index.js:160:15),
promise: Promise { } }

Please help

@appigram
Copy link

appigram commented Sep 9, 2017

@thejameskyle @anilanar Also, serverSideRequirePath (relative path) doesn't work in Meteor, this block

if (typeof metadata.serverSideRequirePath === 'string') {
state.loading = false;
state.loaded = module.require(metadata.serverSideRequirePath);
}

path.join(__dirname, ...) inside import-inspector creates an invalid path to the file

It should be a full path, like
serverSideRequirePath: '/home/projects/react-test/imports/ui/components/Posts/BestPosts.jsx'
I think, we can have an option to set full path from client, maybe like in previous versions?

@kettanaito
Copy link

kettanaito commented Sep 19, 2017

I am having similar issue with SSR.

1. Without babel-plugin-dynamic-import-node there is no attempt to load a module during SSR.

Adding the plugin demonstrates that the prompt is fired, however, it leads to the issue number 2.

2. Path composition of serverSideRequirePath is wrong.

From the attempts of the server logs it is evident that Loadable tries to require a module. The problem is that the path to the required module is relative, and relative to the file where it was imported/required. Consider this:

// AsyncComponent.js
import Loadable from 'react-loadable';
import { Loader } from 'app.components';

export default function AsyncComponent(promise, options) {
  return Loadable({
    loader: promise,
    loading: Loader,
    delay: 500,
    ...options
  });
}
// src/client/Container.jsx
const AsyncFrontpage = AsyncComponent(() => import(/* webpackChunkName: "frontpage" */'./pages/Frontpage'));

During SSR:

Unhandled rejection Error: Cannot find module './pages/Frontpage'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at eval (webpack:///./src/client/Container.jsx?:31:14)
From previous event:
    at eval (webpack:///./src/client/Container.jsx?:30:59)
    at runCallback (timers.js:649:20)
    at tryOnImmediate (timers.js:622:5)
    at processImmediate [as _immediateCallback] (timers.js:594:5)
From previous event:
    at eval (webpack:///./src/client/Container.jsx?:29:28)
    at /Users/azakharchenko/Local/react-progressive-app/node_modules/react-loadable/lib/index.js:28:12
    at capture (/Users/azakharchenko/Local/react-progressive-app/node_modules/react-loadable/lib/index.js:21:17)
    at load (/Users/azakharchenko/Local/react-progressive-app/node_modules/react-loadable/lib/index.js:27:18)
    at new LoadableComponent (/Users/azakharchenko/Local/react-progressive-app/node_modules/react-loadable/lib/index.js:149:15)
    at walkTree (/Users/azakharchenko/Local/react-progressive-app/node_modules/react-apollo/react-apollo.umd.js:694:30)
    at walkTree (/Users/azakharchenko/Local/react-progressive-app/node_modules/react-apollo/react-apollo.umd.js:719:13)
    at walkTree (/Users/azakharchenko/Local/react-progressive-app/node_modules/react-apollo/react-apollo.umd.js:719:13)
    at /Users/azakharchenko/Local/react-progressive-app/node_modules/react-apollo/react-apollo.umd.js:729:21
    at forEachSingleChild (/Users/azakharchenko/Local/react-progressive-app/node_modules/react/lib/ReactChildren.js:51:8)
    at traverseAllChildrenImpl (/Users/azakharchenko/Local/react-progressive-app/node_modules/react/lib/traverseAllChildren.js:77:5)
    at traverseAllChildren (/Users/azakharchenko/Local/react-progressive-app/node_modules/react/lib/traverseAllChildren.js:172:10)
    at Object.forEachChildren [as forEach] (/Users/azakharchenko/Local/react-progressive-app/node_modules/react/lib/ReactChildren.js:71:3)
    at walkTree (/Users/azakharchenko/Local/react-progressive-app/node_modules/react-apollo/react-apollo.umd.js:727:28)
    at /Users/azakharchenko/Local/react-progressive-app/node_modules/react-apollo/react-apollo.umd.js:729:21
    at forEachSingleChild (/Users/azakharchenko/Local/react-progressive-app/node_modules/react/lib/ReactChildren.js:51:8)
    at traverseAllChildrenImpl (/Users/azakharchenko/Local/react-progressive-app/node_modules/react/lib/traverseAllChildren.js:77:5)
    at traverseAllChildrenImpl (/Users/azakharchenko/Local/react-progressive-app/node_modules/react/lib/traverseAllChildren.js:93:23)
    at traverseAllChildren (/Users/azakharchenko/Local/react-progressive-app/node_modules/react/lib/traverseAllChildren.js:172:10)

Sometimes it throws the following error:

Unhandled rejection Error: Cannot find module '[object Promise][object Object]'.
    at webpackContextResolve (webpack:///./src/client_^.*$?:199:9)
    at webpackContext (webpack:///./src/client_^.*$?:194:29)
  • Should not expected file path be src/client/pages/Frontpage.jsx?
  • Can it be related with the .jsx extension, instead of .js?

Overall, Loadable looks very promising, but seriously misses full up-to-date examples, including SSR example (couldn't find one, except of the example with flushServerSideRequires which is not accessible from the library anymore).

Update

Upon further investigation, I can see that the compiled code looks correctly:

var AsyncFrontpage = (0, _app.AsyncComponent)(function () {
  return (0, _importInspector.report)(__webpack_require__.e/* import() */(0/*! frontpage */).then(__webpack_require__.bind(null, /*! ./pages/Frontpage */ "./src/client/pages/Frontpage.jsx")), {
    currentModuleFileName: '/Users/azakharchenko/Local/react-progressive-app/src/client/Container.jsx',
    importedModulePath: './pages/Frontpage',
    serverSideRequirePath: _path3.default.join(__dirname, './pages/Frontpage'),
    webpackRequireWeakId: function webpackRequireWeakId() {
      return /*require.resolve*/(/*! ./pages/Frontpage */ "./src/client/pages/Frontpage.jsx");
    }
  });
});

However, __dirname is undefined. It may have to do with webpack config I am using.

Update

__dirname should be available once you set the following in webpack config:

{
  node: {
    __dirname: true
  }
}

Nevertheless, the compiled code has completely correct file reference (in webpackRequireWeakId). Why is it still failing to require it?

@Flavien-Pensato
Copy link

@thejameskyle

This is my compile code of my composent. I have no SSR with it why?

By the way your demo (react-loadable-example) do not provide SSR too.

`var RefreshUniverse = __WEBPACK_IMPORTED_MODULE_2_react_loadable___default()({
loader: function loader() {
return Object(WEBPACK_IMPORTED_MODULE_1_import_inspector["report"])(webpack_require.e/* import() */("refresh").then(webpack_require.bind(null, "../../src/app/views/containers/refreshUniverse.connector.js")), {
currentModuleFileName: '/Users/fpensato/Projects/site-6play-v4/src/app/routes.js',
importedModulePath: './views/containers/refreshUniverse.connector.js',
serverSideRequirePath: __WEBPACK_IMPORTED_MODULE_0_path___default.a.join(__dirname, './views/containers/refreshUniverse.connector.js')
});
},
loading: function loading() {
return null;
}

--
}`

@kettanaito
Copy link

From what I can gather, although currentModuleFileName contains a proper module file name, during the SSR the library requests importedModulePath, which is not absolute. Therefore, it fails to include a module like ./pages/Frontpage.jsx.

It would be really nice to have an official SSR example, since it raises confusion for so many people. Thank you.

@Flavien-Pensato
Copy link

@kettanaito I find my problem its was 2 things.

babel-plugin-dynamic-import-node was not up-to-date.
The order usage of the plugin was wrong because it was erased by another plugin

@kettanaito
Copy link

@Flavien-Pensato could you please post the right order of the plugins, just to be sure? Thanks!

@Flavien-Pensato
Copy link

Server:

  "plugins": [
    [
      "babel-plugin-transform-require-ignore",
      {
        "extensions": [".scss"]
      }
    ],
    "dynamic-import-node",
    ["import-inspector", {
      "serverSideRequirePath": true
    }],
    "transform-runtime",
    "transform-object-assign",
    ["transform-builtin-extend", {
        "globals": ["Error"],
        "approximate": true
    }]
  ]

Client:

plugins: [
    'transform-object-assign',
    [
      'import-inspector',
      {
        webpackRequireWeakId: true,
      },
    ],
    [
      'transform-builtin-extend',
      {
        globals: ['Error'],
        approximate: true,
      },
    ],
  ],

@Flavien-Pensato
Copy link

@kettanaito I think that your AsyncComponent is bad ^^ remove it. Replace it by Loadable should resolve your bad import

@Flavien-Pensato
Copy link

@kettanaito with webpack 3 set context: __dirname in your webpack config file

@kettanaito
Copy link

kettanaito commented Sep 25, 2017

@Flavien-Pensato I don't think there is anything wrong with AsyncComponent. Client-side code splitting works as expected, module paths are generated as expected, and, moreover, it is quite similar to what docs are suggesting to use. I cannot imagine anyone providing Loader component explicitly on each function declaration - that's a huge overkill. You will end up implementing your own wrapper in the end anyway.

I will try the order you have posted, as well as context of webpack. The latter is more promising. Thank you.

@mxstbr
Copy link
Contributor

mxstbr commented Oct 16, 2017

The dynamic-import-node Babel plugin breaks server-side rendering because it delays the import for a tick, which means you'll get empty and/or loading states on your first render since renderToString is synchronous. (it transpiles import().then() into Promise.resolve().then(() => require()))

With the newest release of react-loadable I've been able to use server-side rendering + codesplitting perfectly fine with the syntax-dynamic-import Babel plugin. It takes care of making sure the import is synchronous on the server and asynchronous on the client, so the only thing needed now is syntax-dynamic-import to make sure Babel understands dynamic imports and doesn't throw an error on the server.

@jamiebuilds
Copy link
Owner

I am deleting every comment unrelated to this issue. Further comments like this will result in banning from all of my repositories. I gave you my answer, respect it or fuck off.

Repository owner deleted a comment from bertho-zero Oct 16, 2017
Repository owner deleted a comment from anilanar Oct 16, 2017
Repository owner deleted a comment from anilanar Oct 16, 2017
Repository owner deleted a comment from bertho-zero Oct 16, 2017
@kettanaito
Copy link

kettanaito commented Oct 17, 2017

@mxstbr, may I paraphrase: so using syntax-dynamic-import on the client, and not using dynamic-import-node on the server now solves the issue? Is that correct?

@mxstbr
Copy link
Contributor

mxstbr commented Oct 17, 2017

Sorry for being unclear: Use babel-plugin-syntax-dynamic-import if Babel throws a SyntaxError for your dynamic import statements import(). (which is likely happening on the server, but could also happen on the client)

You don't need any other Babel plugins other than react-loadable/babel, and definitely don't use dynamic-import-node or dynamic-import-webpack as they break react-loadable.

Is that clear?

@oviava
Copy link

oviava commented Oct 18, 2017

@mxstbr for some reason that I don't fully understand yet I do need babel-plugin-syntax-dynamic-import for jest - still trying to understand some of this stuff

@bertho-zero
Copy link
Contributor

bertho-zero commented Oct 18, 2017

This module works wonders, I use babel-plugin-dynamic-import-node on the server only, with react-loadable/loader.

The SSR and lazy loading works fine.

Note: Another mistake that I made is this:

<ConnectedRouter>
  <Loadable.Capture>
    <Routes />
  </Loadable.Capture>
<ConnectedRouter>

rather:

<Loadable.Capture>
  <ConnectedRouter>
    <Routes />
  <ConnectedRouter>
</Loadable.Capture>

This had the effect of loading all the chunks on first load on client.

@jsonnull
Copy link

Sorry for being unclear: Use babel-plugin-syntax-dynamic-import if Babel throws a SyntaxError for your dynamic import statements import(). (which is likely happening on the server, but could also happen on the client)

@mxstbr I'm getting the syntax error for dynamic import statements on the server, even with the syntax plugin added. I wasn't getting these when I was using babel-plugin-dynamic-import-node, but the reporting from the webpack plugin was not working correctly. Can you share a .babelrc for a working environment perhaps?

@mxstbr
Copy link
Contributor

mxstbr commented Oct 26, 2017

Then that plugin isn't running 😊 The whole point of the syntax plugin is so that Babel doesn't throw a syntax error anymore.

@jsonnull
Copy link

@mxstbr In addition to my .babelrc, I can invoke like this, still getting the syntax error:

babel-node --plugins syntax-dynamic-import ./src/server/build/

What would the next step be to debug this?

@weishiji
Copy link

weishiji commented Nov 11, 2017

I have two page for code split

const Home = Loadable({
  loader : () => import('./pages/Home'),
  loading : Loading,
});

const Creative = Loadable({
  loader : () => import('./pages/creative'),
  loading : Loading,
});

here is my .babelrcfile

 ["import-inspector", {
      "serverSideRequirePath": true,
      "webpackRequireWeakId" : true
    }],
    "dynamic-import-webpack",
    "react-loadable/babel",

I use React Route V4. when the Page is Reload,SSR and Code Split worked fine,But when i jump to another page by React Router,The Page will has an big error like:

VM632509:34 Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object.

Check the render method of `LoadableComponent`.

@kettanaito
Copy link

kettanaito commented Nov 11, 2017

@weishiji doesn't seem to be related to the react-loadable, but rather to one of your components. Cannot say more without seeing them.

The error itself means that you are trying to render what is not a React component, but an Object. The printed error has LoadableComponent in it because this is the end place where your components are being rendered. So a good place to start is to make sure Loading, pages/Home and pages/creative export a valid React component.

@tomatau
Copy link

tomatau commented Dec 4, 2017

Hello, great library!

I have a SSR working, but the react-loadable/plugin only works for the server (in babel runtime) and not the webpack bundle.

I've tried various combinations of with and without dynamic import plugins, with an without syntax dynamic imports with the loadable plugin, with and without import inspectors... nothing seems to quite add up. Including this #35 (comment)

The only way I can get it to work completely is by manually adding the webpack and modules options.

webpack babel config: https://github.com/tomatau/breko-hub/blob/master/src/config/webpack.base.config.js#L94-L116

Loadable routes: https://github.com/tomatau/breko-hub/blob/master/src/app/components/App/App.js#L16-L42

SSR: https://github.com/tomatau/breko-hub/blob/master/src/server/middleware/render-app.js#L27-L32

The update to the README in this PR doesn't seem to offer a suggestion that works for me either.

@jljorgenson18
Copy link

In case anyone was still having issues with this, I was still having issues running React code on the server even after using syntax-dynamic-import. The way the babel plugin for react-loadable works is that it looks for a dynamic import and then decorates the react-loadable options if react-loadable is included in that module. Because of this, you can use the dynamic-import-node plugin "after" you apply react-loadable/babel and then everything should work fine on the server. My babelrc file now looks like this.

{
  "env": {
    "server": {
      "presets": ["react"],
      "plugins": [
        "react-loadable/babel",
        "dynamic-import-node",
        "transform-class-properties",
        "transform-object-rest-spread",
        "transform-es2015-modules-commonjs",
        "babel-plugin-root-import",
        [
          "babel-plugin-styled-components",
          {
            "ssr": true
          }
        ]
      ]
    },
    "test-coverage": {
      "presets": ["react"],
      "plugins": [
        "react-loadable/babel",
        "dynamic-import-node",
        "transform-class-properties",
        "transform-object-rest-spread",
        "istanbul",
        "transform-es2015-modules-commonjs",
        "babel-plugin-root-import",
        [
          "babel-plugin-styled-components",
          {
            "ssr": true
          }
        ]
      ]
    },
    "dev-webpack": {
      "presets": [
        [
          "env",
          {
            "targets": {
              "browsers": ["> 1%", "IE >= 10"]
            },
            "modules": false,
            "useBuiltIns": "entry"
          }
        ],
        "react"
      ],
      "plugins": [
        "syntax-dynamic-import",
        "react-hot-loader/babel",
        "react-loadable/babel",
        "transform-class-properties",
        "transform-object-rest-spread",
        "babel-plugin-root-import",
        [
          "babel-plugin-styled-components",
          {
            "ssr": true
          }
        ]
      ]
    },
    "prod-webpack": {
      "presets": [
        [
          "env",
          {
            "targets": {
              "browsers": ["> 1%", "IE 11"]
            },
            "modules": false,
            "useBuiltIns": "entry",
            "debug": false
          }
        ],
        "react"
      ],
      "plugins": [
        "syntax-dynamic-import",
        "react-loadable/babel",
        "transform-class-properties",
        "transform-object-rest-spread",
        "babel-plugin-root-import",
        [
          "babel-plugin-styled-components",
          {
            "ssr": true
          }
        ]
      ]
    }
  }
}

@unclechong
Copy link

unclechong commented Feb 6, 2018

Comment resolved by @jamiebuilds


index.js - Object.assign() why not ' || ' ?
IE don't render

@kettanaito
Copy link

Thank you everybody for contributing to this discussion.

@jamiebuilds, could you please write a full list of babel plugins needed for react-loadable to work? It's confusing right now - different people use different set of plugins:

  • some use just react-loadable/babel
  • some use react-loadable/babel + syntax-dynamic-import
  • some add import-inspector to those above too

Could you please just give a full example at that? Thanks.

@NandoSangenetto
Copy link

NandoSangenetto commented Feb 28, 2018

Actually, it would be nice if we had a real-world example without babel-node and with Webpack 4 and it's updated plugins.

@andrebautista
Copy link

I was bitten by eslint with a Parsing error: Unexpected token import even though the code was working properly. If the error is persistent and you're using eslint in your build, try commenting that out and see what a fresh webpack build does. If the error goes away and you've been screwed by eslint also then you'll want to check out the babel-eslint package.

@guzhongren
Copy link

image
image
What's wrong???

my repo & test component

@tajo tajo closed this Aug 9, 2018
@jaybe78
Copy link

jaybe78 commented Oct 22, 2018

@NandoSangenetto
https://github.com/jaybe78/react-loadable
Forked and use babel 7 and webpack 4

@tomatau
Copy link

tomatau commented Oct 23, 2018

@jaybe78 Could you publish your fork on npm? You can prefix your name to it as a scope and specify public when publishing. Maybe even as a dist whilst you're in some beta/rc for these changes!

@jaybe78
Copy link

jaybe78 commented Oct 23, 2018

@tomatau ok I will

@jaybe78
Copy link

jaybe78 commented Oct 23, 2018

@tomatau
please check this out https://www.npmjs.com/package/jaybe-react-loadable
I'm willing to maintain the fork if needed.
Let's get the community together to improve the library.
Also let me know if that version fixes the issues you're facing
Please find an example here https://github.com/jaybe78/loadable-example/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.