-
-
Notifications
You must be signed in to change notification settings - Fork 381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ssr not working with webpack 4.0.0-beta1 #46
Comments
I haven't tested Webpack 4 yet. Thanks for reporting! |
I tested it with Webpack 4 and it works, anyway it still in beta and loadable-components is not Webpack dependent so it should not be impacted. I hope your issue will be solved soon. |
@neoziro file c1.js import { Component, createElement } from 'react'
export default props => createElement( 'p', {}, 'hello' ) file main.js import { createElement } from 'react'
import loadable from 'loadable-components'
import { getLoadableState } from 'loadable-components/server'
const View = loadable( () => import( /* webpackChunkName: "main.view" */ './c1.js' ) )
const main = async () => {
try {
const loadableState = await getLoadableState( createElement( View ) )
console.log( loadableState )
} catch ( error ) {
console.error( error )
}
}
main() output: DeferredState { tree: { children: [ [Object] ] } } - okfile main.mjs import * as React from 'react'
const createElement = React.default.createElement
import * as LoadableComponents from 'loadable-components'
const loadable = LoadableComponents.default.default
import * as LoadableComponentsServer from 'loadable-components/server'
const getLoadableState = LoadableComponentsServer.default.getLoadableState
const View = loadable( () => import( /* webpackChunkName: "main.view" */ './c1.js' ) )
const main = async () => {
try {
const loadableState = await getLoadableState( createElement( View ) )
console.log( loadableState )
} catch ( error ) {
console.error( error )
}
}
main() which gives me{ Error: loadable-components: modules entry is missing, your are probably missing `loadable-components/babel`
at /Users/artemxgruden/projectsm2/node-views-provider-template/node_modules/loadable-components/dist/loadable-components.server.cjs.js:153:17
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:160:7)
at Function.Module.runMain (module.js:703:11)
at startup (bootstrap_node.js:190:16)
at bootstrap_node.js:662:3 queryErrors: [ [Circular] ] } my webpack 4 configuration for server: const nodeExternals = require( 'webpack-node-externals' )
module.exports = ( { NODE_ENV, PORT, VIEW_TYPE, DATA_PROVIDER }, webpack, joinPath ) => ( {
target: 'node',
externals: [ nodeExternals() ],
node: {
__dirname: true
},
entry: {
main: joinPath( `./unbundled/server/main.mjs` ),
// main: joinPath( `./unbundled/server/main.js` ),
},
output: {
path: joinPath( `./bundled/server/` ),
filename: '[name].js',
},
resolve: {
modules: [
'node_modules',
joinPath( './unbundled/' ),
],
extensions: [ '.mjs', '.js', '.json' ],
},
devtool: 'source-map',
optimization: {
splitChunks: {
chunks: 'all'
}
},
plugins: [
new webpack.DefinePlugin( {
'process.env': {
'NODE_ENV': JSON.stringify( NODE_ENV ),
'PORT': JSON.stringify( PORT ),
'RUNNING_ENV': JSON.stringify( 'SERVER' ),
'DATA_PROVIDER': JSON.stringify( DATA_PROVIDER ),
'VIEW_TYPE': JSON.stringify( VIEW_TYPE )
}
} ),
],
module: {
rules: [
{
test: /\.(js|mjs)$/,
use: [
{
loader: 'babel-loader',
options: { plugins: [ 'loadable-components/babel' ] }
}
],
}
]
},
} ) |
@neoziro Hello! |
@artemxgruden no, I am sorry I don't see what could be the problem. |
Here's a link to a test project - https://github.com/gcardella/react-universal so you can understand the problem better. src/server/render.js has the call to See comments in the webpack.server.config.js. I am not able to load components using ssr due to the error below: Error on server:
webpack.server.config.js:
|
@jcardella please check @neoziro thank you, I have no problems with node 9.8.0, since node 9.6.0 has support dynamic import feature module versions: I have no webpack configuration for server, only for client module: {
rules: [
{
test: /\.(js|mjs)$/,
use: [
{
loader: 'babel-loader',
options: { plugins: [ 'loadable-components/babel' ] }
}
],
}
]
}, |
I have node -v 9.9.0 ... I don't think the problem is with loadable-components. I think the problem is with loadable-components/babel or babel-plugin-dynamic-import-node not being webpack 4 ready? If I rollback webpack to ver 3.x and loadable-components to ver 0.2.0, everything works without errors. |
For Webpack: only |
hi @neoziro still not working when get ssr markup from node without webpack bundling c1.mjs import * as React from 'react'
const createElement = React.default.createElement
export default props => createElement( 'p', {}, 'hello' ) main.mjs // import initializeProvider from './initializeProvider.mjs'
// initializeProvider()
import * as React from 'react'
const createElement = React.default.createElement
const Component = React.default.Component
import * as ReactDOMServer from 'react-dom/server'
const renderToNodeStream = ReactDOMServer.default.renderToNodeStream
const renderToString = ReactDOMServer.default.renderToString
const renderToStaticMarkup = ReactDOMServer.default.renderToStaticMarkup
import * as LoadableComponentsServer from 'loadable-components/server'
const getLoadableState = LoadableComponentsServer.default.getLoadableState
import * as LoadableComponents from 'loadable-components'
const loadable = LoadableComponents.default.default
import c1 from './c1.mjs'
const c1l = loadable( () => import( /* webpackChunkName: "c1" */ './c1.mjs' ) )
console.info( c1l )
console.info( 'markup', renderToStaticMarkup( createElement( c1 ) ) )
console.info( 'markupl', renderToStaticMarkup( createElement( c1l ) ) ) log
markup is empty string |
You have to load components server-side using |
@neoziro thank you, my mistake main.mjs now import * as React from 'react'
const createElement = React.default.createElement
const Component = React.default.Component
import * as ReactDOMServer from 'react-dom/server'
const renderToNodeStream = ReactDOMServer.default.renderToNodeStream
const renderToString = ReactDOMServer.default.renderToString
const renderToStaticMarkup = ReactDOMServer.default.renderToStaticMarkup
import * as LoadableComponentsServer from 'loadable-components/server'
const getLoadableState = LoadableComponentsServer.default.getLoadableState
import * as LoadableComponents from 'loadable-components'
const loadable = LoadableComponents.default.default
const c1l = loadable( () => import( /* webpackChunkName: "c1" */ './c1.mjs' ), {
modules: [ './c1.mjs' ],
} )
const main = async () => {
const composition = createElement( c1l )
getLoadableState( composition ).then( app => {
console.info( 'markup', renderToString( composition ) )
} ).catch( e => {
console.log( e )
} )
}
main() webpack 4 config for node server const nodeExternals = require( 'webpack-node-externals' )
module.exports = ( { NODE_ENV, PORT, VIEW_TYPE, MACHINE }, webpack, joinPath ) => ( {
target: 'node',
externals: [ nodeExternals( {
whitelist: [
],
} ) ],
node: {
__dirname: true
},
entry: {
main: joinPath( `./unbundled/server/main.mjs` ),
},
output: {
path: joinPath( `./bundled/server/` ),
filename: '[name].js',
},
resolve: {
modules: [
'node_modules',
joinPath( './unbundled/' )
],
extensions: [ '.mjs', '.js', '.json' ],
},
devtool: 'source-map',
optimization: {
splitChunks: {
chunks: 'all'
}
},
plugins: [
new webpack.DefinePlugin( {
'process.env': {
'NODE_ENV': JSON.stringify( NODE_ENV ),
'PORT': JSON.stringify( PORT ),
'RUNNING_ENV': JSON.stringify( 'SERVER' ),
'MACHINE': JSON.stringify( MACHINE ),
'VIEW_TYPE': JSON.stringify( VIEW_TYPE )
}
} ),
],
module: {
rules: [
{
test: /\.(js|mjs)$/,
use: [
{
loader: 'babel-loader',
options: { plugins: [ 'loadable-components/babel' ] },
}
],
}
]
},
} ) "webpack": "^4.2.0", |
@neoziro but I have error when running main.mjs without webpack bundling
|
@neoziro Please add support for new getDerivedStateFromProps react 16.3 method |
@neoziro Please up static methods of wrapped components. c - ƒ LoadableComponent() if ( c && c.Component && c.Component.preloadDataState && Object.prototype.toString.call( c.Component.preloadDataState === '[object AsyncFunction]' ){
...
} |
@artemxgruden I do not understand the last one. Can you describe it completely in a different issue? |
export const Layout = loadable( () => import( / webpackChunkName: "main.layout" / './components/layouts/container.mjs' ) )
first error:
loadable-components: modules entry is missing, your are probably missing
loadable-components/babel
then I set in webpack server config:
then another error:
Error: Cannot find module './components/layouts/container.mjs'
but all works with webpack 3.10.0
The text was updated successfully, but these errors were encountered: