in Education by
Does server-side rendering with react-loadable work with Webpack 4 and Babel 7? I've been unable to get it working successfully while following the instructions. After following just the client-side steps, Webpack correctly outputs separate chunks for each loadable component and this is reflected when I load the page in the browser (ie: the chunks are lazy-loaded). After following all the SSR steps, however, the server throws the following error: Error: Not supported at loader (/Projects/test-project/web/routes/index.js:50:15) at load (/Projects/test-project/web/node_modules/react-loadable/lib/index.js:28:17) at init (/Projects/test-project/web/node_modules/react-loadable/lib/index.js:121:13) at flushInitializers (/Projects/test-project//web/node_modules/react-loadable/lib/index.js:310:19) at /Projects/test-project/web/node_modules/react-loadable/lib/index.js:322:5 at new Promise () at Function.Loadable.preloadAll (/Projects/test-project/web/node_modules/react-loadable/lib/index.js:321:10) at Object.preloadAll (/Projects/test-project/web/server.js:15:10) at Module._compile (internal/modules/cjs/loader.js:702:30) at Module._compile (/Projects/test-project/web/node_modules/pirates/lib/index.js:83:24) My routes/index.js file: import React from 'react'; import Loadable from 'react-loadable'; import Loading from '../components/Loading'; export default [ { path: '/', component: Loadable({ loader: () => import('./controllers/IndexController'), loading: Loading, }), exact: true, }, { path: '/home', component: Loadable({ loader: () => import('./controllers/HomeController'), loading: Loading, }), exact: true, }, ... ]; This issue on SO is possibly related to the server error I'm seeing above, but provided even less info. My .babelrc is already using @babel/plugin-syntax-dynamic-import, but I tried adding babel-plugin-dynamic-import-node. This fixes the server issue but Webpack then no longer builds the chunks. I've been unable to find a definitive example to get this working. There is conflicting info out there about proper setup. For example, the react-loadable README says to use the included react-loadable/babel plugin, while this post by the lib author says to use babel-plugin-import-inspector. This PR seemed to be attempting to address Webpack 4 issues but was closed, and the forked lib appeared to have issues as well. I am using: Babel 7 Node 10.4 React 16.5 React-Loadable 5.5 Webpack 4 JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
I had the exact same problem today. After adding dynamic-import-node to the plugins of my .babelrc the server worked, but webpack wasn't creating the chunks. I then removed it again from my .babelrc and moved it to my server script with @babel/register. My server script now looks like this: require( "@babel/register" )({ presets: ["@babel/preset-env", "@babel/preset-react"], plugins: ["dynamic-import-node"] }); require( "./src/server" ); I hope this helps ;)

Related questions

0 votes
    Quick Summary of my question: Does Gulp 3.6.0 dest() handle glob-base the same way as 4.0.0? ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 19, 2022 in Education by JackTerrance
0 votes
    I'm trying to make a form-maker with Node.Js and MongoDB but confused about the data structure. ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    I'm trying to debug my nodejs app using node-inspector. But Google Chrome doesn't show the code. ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 11, 2022 in Education by JackTerrance
0 votes
    I have been looking at using the ssh2 module for sftp shipping of logs. However the cloud service hosting ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
0 votes
    i'm trying to test with jest this route on my node microservice. At the initalisation of my microservice ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I've been putzing with trying to call the jobs.Insert bigquery rest api endpoint with node (the jobs. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    Hi I'm using ffmpeg to concatenate several mp4 files that I downloaded. Usually they don't have the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    Here is my data: { { "_id" : ObjectId("623a92139e19f99295167786"), "headline" : "headline1", " ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    so i'm reviewing and practicing making rest api with node mongoose and express. I'm having problem making ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 14, 2022 in Education by JackTerrance
0 votes
    How should I handle /_ah/start and /_ah/stop requests? Right now they're just getting 404s. Also, ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    The napi_create_date function appeared in Node.js starting with 11.11.0 version. https://nodejs.org/api/n- ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    Step 1: server I've created a simple server with Node & Socket.io which declares a namespace under ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 3, 2022 in Education by JackTerrance
0 votes
    I'm trying to use node to print the Serial from Arduino uno connected to USB I have a file script ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 30, 2022 in Education by JackTerrance
0 votes
    I have yet another "Can't set headers after they are sent." problem. I've created a post router ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 30, 2022 in Education by JackTerrance
0 votes
    My websocket application accepting connections like this: wsServer.on('request', function(request) { console.log( ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 8, 2022 in Education by JackTerrance
...