question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: [universal-webpack] Your server source file must export a function. Got [ 'libserver' ]

See original GitHub issue

when I added runtimeChunk to the optimization Obj or splitChunks{..} it throw this error

this is my webpack config: `import path from ‘path’; import webpack from ‘webpack’; import WebpackNotifierPlugin from ‘webpack-notifier’; import webpackMerge from ‘webpack-merge’; import CleanWebpackPlugin from ‘clean-webpack-plugin’; import headerFooterManifestJSON from ‘@wehkamp/blaze-lib-headerfooter-components/lib/manifest.json’; import UglifyJsPlugin from ‘uglifyjs-webpack-plugin’; import MiniCssExtractPlugin from ‘mini-css-extract-plugin’; import OptimizeCSSAssetsPlugin from ‘optimize-css-assets-webpack-plugin’; import CompressionPlugin from ‘compression-webpack-plugin’; import { BundleAnalyzerPlugin } from ‘webpack-bundle-analyzer’; import FriendlyErrorsWebpackPlugin from ‘friendly-errors-webpack-plugin’; import SpeedMeasurePlugin from ‘speed-measure-webpack-plugin’;

process.noDeprecation = true;

const target = process.env.npm_lifecycle_event; const development = process.env.NODE_ENV === ‘development’; const smp = new SpeedMeasurePlugin();

const commonConfig = webpackMerge([{ devtool: ‘cheap-module-source-map’, mode: development ? ‘development’ : ‘production’, entry: path.resolve(_dirname, ‘…’, ‘src’, ‘app’, ‘index’), context: path.resolve(dirname, ‘…’), output: { path: path.resolve(dirname, ‘…’, ‘dist’, ‘public’), filename: ‘[name].[hash:8].js’, libraryTarget: ‘umd’, }, stats: { chunkGroups: true, chunks: true, }, module: { rules: [{ test: /wehkamp/ui-/, loader: ‘babel-loader’, }, { test: /.js$/, loader: ‘babel-loader’, exclude: /node_modules/, options: { cacheDirectory: true, }, }, { test: /.(ttf|eot|svg|woff(2)?)$/, use: [{ loader: ‘file-loader’, options: { name: ‘[name].[hash:8].[ext]’, }, }], }, { test: /.(jpe?g|png|gif)$/i, use: [{ loader: ‘url-loader’, options: { limit: 4096, name: ‘[name].[hash:8].[ext]’, }, }], }, { test: /.(graphqls?|gql)$/, exclude: /node_modules/, loader: ‘graphql-tag/loader’, }, { test: /.(css|scss)$/, use: [{ loader: MiniCssExtractPlugin.loader, }, { loader: ‘css-loader’, options: { modules: true, importLoaders: 1, localIdentName: '[name][local][hash:base64:5]‘, discardComments: true, sourceMap: true, }, }, { loader: ‘postcss-loader’, options: { sourceMap: true, }, }, { loader: ‘sass-loader’, options: { outputStyle: ‘compressed’, sourceMap: true, }, }, ], }, ], }, plugins: [ new webpack.ProgressPlugin(), new WebpackNotifierPlugin(), new webpack.DefinePlugin({ webpackVars: { headerFooterManifest: JSON.stringify(headerFooterManifestJSON), }, ‘process.env.NODE_ENV’: JSON.stringify(process.env.NODE_ENV), }), new MiniCssExtractPlugin({ filename: ‘[name].[contenthash:8].css’, chunkFilename: ‘[id].[hash:8].css’, }), new webpack.ContextReplacementPlugin( /graphql-language-service-interface[\/]dist$/, new RegExp(’^\./.\.js$‘), ), ], optimization: { runtimeChunk: ‘single’, namedModules: true, noEmitOnErrors: true, splitChunks: { cacheGroups: { vendor: { test: /[\/]node_modules[\/]/, name: ‘vendors’, chunks: ‘all’, }, }, }, minimizer: [ new UglifyJsPlugin({ sourceMap: true, cache: true, parallel: true, uglifyOptions: { compress: { warnings: false, }, output: { comments: false, }, }, }), ], }, resolve: { extensions: [’', ‘.js’, ‘.jsx’], }, }]);

if (target === ‘bundle’) { commonConfig.plugins.push( new BundleAnalyzerPlugin({ analyzerPort: 7777, }), ); }

const productionConfig = webpackMerge([{ plugins: [ new CleanWebpackPlugin([‘dist’]), new CompressionPlugin(), new webpack.LoaderOptionsPlugin({ minimize: true, debug: false, options: { context: path.resolve(__dirname, ‘…’), babel: { babelrc: true, }, }, }), ], optimization: { minimizer: [ new OptimizeCSSAssetsPlugin({}), ], }, }]);

const developmentConfig = webpackMerge([{ plugins: [ new FriendlyErrorsWebpackPlugin(), ], }]);

const config = development ? developmentConfig : productionConfig; const mergeConfig = webpackMerge(commonConfig, config);

const configuration = smp.wrap(mergeConfig); // const configuration = smp.wrap(webpackMerge(…commonConfig, …config));

export default configuration;`

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
catamphetaminecommented, Jan 28, 2019

@yousefallaban

Ok, but it’s possible to use it with universal-webpack. ?

Won’t able to tell you that. I only tested universal-webpack with generic cases. Your case seems to be a complex one.

0reactions
yousefallabancommented, Jan 28, 2019

@catamphetamine Ok, but it’s possible to use it with universal-webpack. ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - webpack: import + module.exports in the same ...
I got the error Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>' . Turns out that changing import $...
Read more >
export - JavaScript - MDN Web Docs
The export declaration is used to export values from a JavaScript module. Exported values can then be imported into other programs with the...
Read more >
Loading data • Docs • SvelteKit
A load function in a +page.js file runs both on the server and in the browser. If your load function should always run...
Read more >
Node Module Exports Explained - freeCodeCamp
Node Module Exports Explained – With JavaScript Export Function Examples ... module from a JS file with module.exports being the exported ...
Read more >
Understanding Modules and Import and Export Statements in ...
As the importance of JavaScript in web development grows, there is a bigger need to ... Open the functions.js file and add the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found