Webpack: 'bindings is not defined' - javascript

i'm building Application with nodejs (server) and reactjs (client)..
All fine, but recently i have some problem with webpack.. after that i run webpack i have error in a browser console:
Uncaught ReferenceError: bindings is not defined
I've got no idea about this issue.. any help ?
Here my webpack config:
var ExtractTextPlugin = require('extract-text-webpack-plugin')
var webpack = require('webpack')
module.exports = {
entry: [
'babel-polyfill',
'./src/client/index.js'
],
devtool: 'source-map',
output: {
path: './src/static/js/',
filename: 'bundle.js'
},
module: {
loaders: [{
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['react', 'es2015', 'stage-1']
}
}, {
test: /\.scss$/,
loader: ExtractTextPlugin.extract('css!sass')
}, {
test: /\.json$/,
loader: "json-loader"
}],
noParse: /lie\.js$|\/leveldown\//
},
node: {
net: 'empty',
fs: 'empty',
dns: 'empty'
},
resolve: {
extensions: ['', '.js', '.jsx']
},
plugins: [
new ExtractTextPlugin('../css/style.css', {
allChunks: true
}),
new webpack.ContextReplacementPlugin(/bindings$/, /^$/)
],
externals: ["bindings"]
}

Related

ChunkLoadError: Loading chunk 597 failed. React webpack

i am creating react library. when i use that libary in my project i am facing this issue
(https://i.stack.imgur.com/HymU0.png)](https://i.stack.imgur.com/HymU0.png)
This is my webpack.config file
var path = require("path");
module.exports = {
mode: "production",
entry: "./tables.js",
output: {
// path: path.resolve("build"),
libraryTarget: "umd",
path: __dirname + '/dist',
publicPath: '/',
filename: 'index.js',
},
module: {
rules: [
{
test: /\.jsx?$/, exclude: /node_modules/
, use: {
loader: 'babel-loader',
options: {
presets: [
['#babel/preset-env', { targets: "defaults" }, '#babel/preset-react'
]
],
plugins: ['#babel/plugin-proposal-class-properties']
}
}
},
{
test: /\.(s*)css$/,
use: ['style-loader', 'css-loader', 'sass-loader']
},
]
},
externals: {
'react': 'react',
}
};
i am expecting to load this chunk in my project without facing this issue

#babel/polyfill - is deprecated. Please, use required parts of `core-js` and `regenerator-runtime/runtime` separately

I am having an issue trying to 'run serve' with a React-App I am working on. I am getting a bunch of error messages but I think are mainly due to this one error -
#babel/polyfill is deprecated. Please, use required parts of 'core-js' and 'regenerator-runtime/runtime' separately.
This is a webpack.config.dev.js and webpack.config.js file
const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: { main: './src/index.tsx' },
mode: 'development',
externals: {
react: 'React',
'react-dom': 'ReactDOM',
'react-router': 'ReactRouter',
},
target: 'web',
module: {
rules: [
{
test: /\.tsx?$/,
use: [
{
loader: 'babel-loader',
options: {
presets: [
[
'#babel/preset-env',
{
useBuiltIns: 'entry',
corejs: 3,
},
],
],
},
},
{ loader: 'ts-loader' },
],
},
{
test: /\.(jsx?)$/,
use: [
{
loader: 'babel-loader',
options: {
presets: [
[
'#babel/preset-env',
{
useBuiltIns: 'entry',
corejs: 3,
},
],
],
},
},
],
},
{
test: /\.(s*)css$/,
use: ['style-loader', 'css-loader', 'postcss-loader', 'sass-loader'],
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist'),
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
template: 'src/index.html',
filename: 'index.html',
chunksSortMode: 'auto',
chunks: ['main'],
}),
],
};
Any ideas? Thank you!

document is not defined after running webpack scripts

So I tried creating a boilerplate for an existing project that our company have and after running the script for webpack,
it generated a ./dist/server.js however, when I run it from node, I am getting this document not found error. Please let me know if you need a code snippet of a specific file.
ERROR
){var n=(0,r.renderToString)(o().createElement(Wn,null));a.send('\n <!DOCTYPE html>\n <html>\n <head>\n </head>\n <body style="margin:0">\n <div id="root">'+n+'</div>\n </body>\n <script src="main.bundle.js" defer><\/script>\n </html>\n')})),Hn.listen(3e3,(function(){console.log("app listening on port 3000!")}))})()})();
ReferenceError: document is not defined
code above is a long one line code which I had to cut off
webpack.config.client.js
const path = require('path');
module.exports = {
mode: 'production',
entry: {
main: './src/index.tsx',
},
module: {
rules: [
{
loader: 'ts-loader',
test: /\.(tsx|ts)?$/,
exclude: [/node_modules/],
},
{
test: /\.(scss)$/,
use: ['style-loader', 'css-loader', 'sass-loader']
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
loader: 'file-loader',
options: {
name: '/src/assets/images/[name].[ext]'
}
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
loader: "file-loader"
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
}
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
output: {
filename: '[name].bundle.js',
sourceMapFilename: '[file].map',
path: path.resolve(__dirname, 'dist/public'),
},
};
webpack.config.server.js
const path = require('path');
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const nodeExternals = require('webpack-node-externals');
const { join } = require('lodash');
module.exports = {
mode: 'production',
entry: {
server: './server/index.tsx',
},
target: 'node',
node: {
__dirname: false,
__filename: false,
},
externals: [nodeExternals()],
plugins: [
new HtmlWebpackPlugin({
filename: 'index.html',
title: "Test",
template: './src/index.html'
})
],
module: {
rules: [
{
loader: 'ts-loader',
test: /\.tsx?$/,
options: {
transpileOnly: true,
},
exclude: [/node_modules/],
},
{
test: /\.(s*)css$/,
use: ['style-loader', 'css-loader', 'sass-loader']
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
loader: 'file-loader',
options: {
name: '/src/assets/images/[name].[ext]'
}
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
loader: "file-loader"
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
}
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist'),
},
};

What can i do to get few output files by webpack

My Webpack compiling all my project in one index.js. What can I do to get javascript code in "index.js" and css code in "style/index.css"?
My webpack.config.js:
`
var path = require('path');
module.exports = {
entry: './entry.js',
output: {
filename: 'testApp/www/index.js'
},
resolve: {
extensions: ['.js', '.jsx', '.json']
},
module: {
loaders: [
{ test: /\.jsx?$/,
loader: 'babel-loader',
include: path.resolve(__dirname,` "app"),
query:
{
presets:['react', 'es2015', 'stage-0']
}
},
{
test: /\.scss$/,
loader: 'style-loader!css-loader!sass-loader'
}
]
}
};
`
You can use ExtractTextPlugin
On console run npm install --save-dev extract-text-webpack-plugin
In your webpack.config.js
module.exports = {
entry: './entry.js',
output: {
filename: 'testApp/www/index.js'
},
resolve: {
extensions: ['.js', '.jsx', '.json']
},
module: {
loaders: [
{ test: /\.jsx?$/,
loader: 'babel-loader',
include: path.resolve(__dirname, "app"),
query:
{
presets:['react', 'es2015', 'stage-0']
}
},
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'sass-loader']
})
}
]
},
plugins: [
new ExtractTextPlugin('style/index.css')
],
};

Getting 'module is not defined' after webpack build when running in browser

AFter building my typescript-react application, I am getting a 'module is not defined'error after running in browser.
Note that I am targeting the electron-renderer. Everything seems to work fine when running using èlectron ., but when I serve it in the browser, it starts showing this error.
var path = require("path")
var webpack = require("webpack")
module.exports = {
debug: true,
devtool: "inline-source-map",
entry: {
index: ["index.tsx", "babel-polyfill", "ts-helpers"]
},
output: {
path: path.resolve(__dirname, "build"),
filename: "[name].js",
libraryTarget: "commonjs2"
},
resolve: {
root: [
path.resolve(__dirname, "src")
],
extensions: ["", ".ts", ".tsx", ".js", ".jsx"]
},
module: {
loaders: [
{
test: /\.tsx?$/,
loaders: [
"babel-loader",
"ts-loader"
]
},
{
test: /\.jsx?$/,
loaders: [
"babel-loader"
]
},
{
test: /\.json$/,
loaders: [
"json-loader"
]
}
]
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development')
})
],
target: "electron-renderer"
}

Categories