configuration has an unknown property 'debug'. These properties are valid - npm

I'm creating an isomorphic React app and currently creating a stack.
When I want to test if everything works well with npm run build, I'm receiving the following mistake :
Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
- configuration has an unknown property 'debug'. These properties are valid:
object { amd?, bail?, cache?, context?, dependencies?, devServer?, devtool?, entry?, externals?, loader?, mode?, module?, name?, node?, optimization?, output?, parallelism?, performance?, plugins?, profile?, recordsInputPath?, recordsOutputPath?, recordsPath?, resolve?, resolveLoader?, serve?, stats?, target?, watch?, watchOptions? }
The 'debug' property was removed in webpack 2.0.0.
Loaders should be updated to allow passing this option via loader options in module.rules.
Until loaders are updated one can use the LoaderOptionsPlugin to switch loaders into debug mode:
plugins: [
new webpack.LoaderOptionsPlugin({
debug: true
})
]
- configuration.resolve.extensions[0] should not be empty.
-> A non-empty string
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! react-isomorphic-app#1.0.0 build: `set NODE_ENV='production' && webpack -p`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the react-isomorphic-app#1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Empeek\AppData\Roaming\npm-cache\_logs\2019-01-17T15_35_03_122Z-debug.log
There is probably some mistakes in webpack config pr package json files, but I don't know what exactly
I've got a "debug" property in my package.json file:
package.json
{
"name": "react-isomorphic-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "set NODE_ENV='production' && webpack -p",
"webpack-devserver": "webpack-dev-server --debug --hot --devtool eval-source-map --output-pathinfo --watch --colors --inline --content-base public --port 8050 --host 0.0.0.0"
},
"author": "",
"license": "ISC",
"dependencies": {
"babel-core": "^6.26.3",
"babel-plugin-transform-decorators-legacy": "^1.3.5",
"babel-polyfill": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"bluebird": "^3.5.3"
},
"devDependencies": {
"babel-loader": "^8.0.5",
"clean-webpack-plugin": "^1.0.0",
"css-loader": "^2.1.0",
"extract-text-webpack-plugin": "^3.0.2",
"file-loader": "^3.0.1",
"html-loader": "^0.5.5",
"json-loader": "^0.5.7",
"less": "^3.9.0",
"less-loader": "^4.1.0",
"postcss-loader": "^3.0.0",
"style-loader": "^0.23.1",
"url-loader": "^1.1.2",
"webpack": "^4.28.4",
"webpack-cli": "^3.2.1",
"webpack-dev-server": "^3.1.14"
}
}
webpack.config.js
global.Promise = require('bluebird');
var webpack = require('webpack');
var path = require('path');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var CleanWebpackPlugin = require('clean-webpack-plugin');
var publicPath = 'http://localhost:8050/public/assets';
var cssName = process.env.NODE_ENV === 'production' ? 'styles-[hash].css' : 'styles.css';
var jsName = process.env.NODE_ENV === 'production' ? 'bundle-[hash].js' : 'bundle.js';
var plugins = [
new webpack.DefinePlugin({
'process.env': {
BROWSER: JSON.stringify(true),
NODE_ENV: JSON.stringify(process.env.NODE_ENV || 'development')
}
}),
new ExtractTextPlugin(cssName)
];
if (process.env.NODE_ENV === 'production') {
plugins.push(
new CleanWebpackPlugin([ 'public/assets/' ], {
root: __dirname,
verbose: true,
dry: false
})
);
plugins.push(new webpack.optimize.DedupePlugin());
plugins.push(new webpack.optimize.OccurenceOrderPlugin());
}
module.exports = {
entry: ['babel-polyfill', './src/client.js'],
debug: process.env.NODE_ENV !== 'production',
resolve: {
root: path.join(__dirname, 'src'),
modulesDirectories: ['node_modules'],
extensions: ['', '.js', '.jsx']
},
plugins,
output: {
path: `${__dirname}/public/assets/`,
filename: jsName,
publicPath
},
module: {
rules: [
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('style-loader', 'css-loader!postcss-loader')
},
{
test: /\.less$/,
loader: ExtractTextPlugin.extract('style-loader', 'css-loader!postcss-loader!less-loader')
},
{ test: /\.gif$/, loader: 'url-loader?limit=10000&mimetype=image/gif' },
{ test: /\.jpg$/, loader: 'url-loader?limit=10000&mimetype=image/jpg' },
{ test: /\.png$/, loader: 'url-loader?limit=10000&mimetype=image/png' },
{ test: /\.svg/, loader: 'url-loader?limit=26000&mimetype=image/svg+xml' },
{ test: /\.(woff|woff2|ttf|eot)/, loader: 'url-loader?limit=1' },
{ test: /\.jsx?$/, loader: 'babel', exclude: [/node_modules/, /public/] },
{ test: /\.json$/, loader: 'json-loader' },
]
},
devtool: process.env.NODE_ENV !== 'production' ? 'source-map' : null,
devServer: {
headers: { 'Access-Control-Allow-Origin': '*' }
}
};
Can you help me to fix this mistake?

Related

Issue in running storybook for vuejs and preact together in one project

I am trying to merge 2 ui components library together for vuejs and preact but getting some issues in storybook. I have successfully run build for both with same script. Now when I tried to create 2 scripts for storybooks of both framework then getting below errors.
When running script yarn storybook:react getting below error-
ERR! TypeError [ERR_INVALID_ARG_TYPE]: The "id" argument must be of type string. Received an instance of Object
ERR! at validateString (internal/validators.js:120:11)
ERR! at Module.require (internal/modules/cjs/loader.js:880:3)
ERR! at require (internal/modules/cjs/helpers.js:74:18)
ERR! at interopRequireDefault (/projects/dwc/node_modules/#storybook/core-common/dist/cjs/presets.js:178:16)
ERR! at getContent (/projects/dwc/node_modules/#storybook/core-common/dist/cjs/presets.js:194:10)
ERR! at loadPreset (/projects/dwc/node_modules/#storybook/core-common/dist/cjs/presets.js:203:20)
ERR! at /projects/dwc/node_modules/#storybook/core-common/dist/cjs/presets.js:256:18
ERR! at Array.reduce (<anonymous>)
ERR! at loadPresets (/projects/dwc/node_modules/#storybook/core-common/dist/cjs/presets.js:255:18)
ERR! at loadPreset (/projects/dwc/node_modules/#storybook/core-common/dist/cjs/presets.js:225:81)
ERR! TypeError [ERR_INVALID_ARG_TYPE]: The "id" argument must be of type string. Received an instance of Object
ERR! at validateString (internal/validators.js:120:11)
ERR! at Module.require (internal/modules/cjs/loader.js:880:3)
ERR! at require (internal/modules/cjs/helpers.js:74:18)
ERR! at interopRequireDefault (/projects/dwc/node_modules/#storybook/core-common/dist/cjs/presets.js:178:16)
ERR! at getContent (/projects/dwc/node_modules/#storybook/core-common/dist/cjs/presets.js:194:10)
ERR! at loadPreset (/projects/dwc/node_modules/#storybook/core-common/dist/cjs/presets.js:203:20)
ERR! at /projects/dwc/node_modules/#storybook/core-common/dist/cjs/presets.js:256:18
ERR! at Array.reduce (<anonymous>)
ERR! at loadPresets (/projects/dwc/node_modules/#storybook/core-common/dist/cjs/presets.js:255:18)
ERR! at loadPreset (/projects/dwc/node_modules/#storybook/core-common/dist/cjs/presets.js:225:81) {
ERR! code: 'ERR_INVALID_ARG_TYPE'
ERR! }
When running script yarn storybook:vue getting below error -
ERR! TypeError: Cannot read property '#<Object>' of undefined
ERR! at Object.webpackFinal (/projects/dwc/.vueStorybook/main.js:19:21)
ERR! at /projects/dwc/node_modules/#storybook/core-common/dist/cjs/presets.js:294:28
ERR! at async Object.webpack (/projects/dwc/node_modules/#storybook/builder-webpack5/dist/cjs/presets/custom-webpack-preset.js:42:28)
ERR! at async starterGeneratorFn (/projects/dwc/node_modules/#storybook/builder-webpack5/dist/cjs/index.js:116:16)
ERR! at async Object.start (/projects/dwc/node_modules/#storybook/builder-webpack5/dist/cjs/index.js:272:14)
ERR! at async Promise.all (index 0)
ERR! at async storybookDevServer (/projects/dwc/node_modules/#storybook/core-server/dist/cjs/dev-server.js:207:28)
ERR! at async buildDevStandalone (/projects/dwc/node_modules/#storybook/core-server/dist/cjs/build-dev.js:120:31)
ERR! at async buildDev (/projects/dwc/node_modules/#storybook/core-server/dist/cjs/build-dev.js:174:5)
**My configurations are below- **
Node Version - 12.22.0
Rollup file -
import babel from 'rollup-plugin-babel';
import multiInput from 'rollup-plugin-multi-input';
import resolve from '#rollup/plugin-node-resolve';
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
import postcss from 'rollup-plugin-postcss';
import alias from '#rollup/plugin-alias';
import path from 'path';
import commonjs from "#rollup/plugin-commonjs";
import vue from "rollup-plugin-vue";
import tsPaths from "rollup-plugin-tsconfig-paths"
const extensions = ['.js', '.jsx', '.ts', '.tsx'];
const reactConfig = {
input: [
'src/react/**/*.{js,jsx,ts,tsx}',
'!**/*/style/**',
'!**/*.stories.tsx',
'!src/react/*.d.ts',
'!src/react/assets/**',
'!**/*.test.js',
],
plugins: [
peerDepsExternal(),
resolve({ extensions, browser: true }),
babel({
extensions,
include: [
'src/react/**/*',
'!**/*.stories.tsx',
'!**/style/**',
'!src/react/*.d.ts',
'!src/react/assets/**',
'!**/*.test.js',
],
exclude: ['node_modules/**', 'src/vue'], // only transpile our source code
}),
postcss(),
multiInput({ relative: 'src/react' }),
tsPaths({ tsConfigPath: 'tsconfig.react.json' }),
],
output: [
{
dir: 'dist/react/cjs',
format: 'cjs',
sourcemap: true,
},
{
dir: 'dist/react/esm',
format: 'esm',
sourcemap: true,
},
],
}
const vueConfig = {
input: "src/vue/index.ts",
output: [
{
format: "cjs",
file: "dist/vue/index.js",
sourcemap: true
},
{
format: "esm",
file: "dist/vue/index.esm.js",
sourcemap: true
}
],
plugins: [
peerDepsExternal(),
resolve(),
vue(),
commonjs(),
postcss(),
tsPaths({ tsConfigPath: 'tsconfig.vue.json' }),
]
}
export default [reactConfig, vueConfig];
Package.json file -
{
"main": "dist/vue/index.js",
"module": "dist/react/cjs/index.js",
"files": [
"dist"
],
"scripts": {
"clean": "rimraf dist",
"build:types": "tsc --emitDeclarationOnly --outDir dist/esm && tsc --emitDeclarationOnly --outDir dist/cjs",
"build:js": "rollup -c",
"build:css": "node-sass -r src/react -o dist/react/esm && node-sass -r src/react -o dist/react/cjs",
"build": "npm run clean && npm run build:js && npm run build:css",
"storybook:react": "start-storybook -p 6006 -c .reactStorybook",
"storybook:vue": "start-storybook -p 6007 -c .vueStorybook",
"build-storybook": "build-storybook"
},
"peerDependencies": {
"classnames": "*",
"preact": "*",
"vue": "^2.6.11",
"vue-class-component": "^7.2.3"
},
"devDependencies": {
"#babel/cli": "7.8.4",
"#babel/core": "^7.17.9",
"#babel/plugin-proposal-class-properties": "7.8.3",
"#babel/preset-env": "^7.16.11",
"#babel/preset-react": "^7.9.4",
"#babel/preset-typescript": "7.9.0",
"#rollup/plugin-alias": "^3.1.0",
"#rollup/plugin-commonjs": "^14.0.0",
"#rollup/plugin-node-resolve": "^9.0.0",
"#storybook/addon-actions": "^6.5.9",
"#storybook/addon-essentials": "^6.5.9",
"#storybook/addon-interactions": "^6.5.9",
"#storybook/addon-links": "^6.5.9",
"#storybook/testing-library": "0.0.13",
"#storybook/vue3": "^6.5.9",
"#types/classnames": "^2.2.10",
"#typescript-eslint/eslint-plugin": "2.28.0",
"#typescript-eslint/parser": "2.28.0",
"#vue/compiler-sfc": "^3.2.33",
"babel-eslint": "10.1.0",
"babel-loader": "^8.2.4",
"eslint": "6.8.0",
"eslint-config-airbnb": "18.1.0",
"eslint-config-airbnb-typescript": "7.2.1",
"eslint-config-prettier": "6.10.1",
"eslint-config-react-app": "5.2.1",
"eslint-import-resolver-typescript": "2.0.0",
"eslint-plugin-flowtype": "4.7.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "6.2.3",
"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-react": "7.19.0",
"eslint-plugin-react-hooks": "2.5.0",
"eslint-plugin-storybook": "^0.5.12",
"eslint-plugin-vue": "^7.0.0-0",
"node-sass": "^7.0.1",
"preact": "^10.4.1",
"prettier": "2.0.4",
"rimraf": "^3.0.2",
"rollup": "^2.70.2",
"rollup-plugin-babel": "4.4.0",
"rollup-plugin-multi-input": "1.1.1",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-postcss": "^3.1.1",
"rollup-plugin-typescript2": "^0.31.2",
"rollup-plugin-vue": "^6.0.0",
"sass-loader": "^8.0.2",
"typescript": "^4.6.3",
"vue": "^3.2.33",
"vue-class-component": "^7.2.6",
"vue-loader": "^16.8.3",
"vue-template-compiler": "^2.6.14"
},
"dependencies": {
"#babel/plugin-proposal-private-methods": "^7.17.12",
"#babel/plugin-proposal-private-property-in-object": "^7.17.12",
"#storybook/builder-webpack5": "^6.5.9",
"#storybook/manager-webpack5": "^6.5.9",
"#storybook/preact": "^6.5.9",
"classnames": "^2.2.6",
"rollup-plugin-tsconfig-paths": "^1.1.8"
}
}
My main.js file configurations are-
.reactStorybook/main.js -
const path = require('path');
const prettierConfig = require('../.prettierrc.js');
module.exports = {
stories: ['../src/react/**/*.stories.tsx', '../src/react/**/*.stories.jsx'],
addons: [
'#storybook/addon-actions',
'#storybook/addon-links',
'#storybook/addon-knobs/register',
{
name: '#storybook/addon-storysource',
options: {
rule: {
// test: [/\.stories\.jsx?$/], This is default
include: [path.resolve(__dirname, '../src/react')], // You can specify directories
},
loaderOptions: {
prettierConfig,
},
},
},
],
webpackFinal: async (config) => {
config.module.rules.push({
test: /\.(ts|tsx)$/,
use: [
{
loader: 'babel-loader',
options: {
presets: ['#babel/preset-env'],
plugins: ['#babel/plugin-proposal-class-properties']
}
},
],
});
config.module.rules.push({
test: /\.stories\.tsx?$/,
loaders: [
{
// adds source decorator into stories
loader: require.resolve('#storybook/source-loader'),
options: { parser: 'typescript' },
},
],
enforce: 'pre',
});
config.module.rules.push({
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'sass-loader'],
include: path.resolve(__dirname, '../src'),
});
config.resolve.alias = {
'#src': path.resolve(__dirname, '../src/react'),
'#components': path.resolve(__dirname, '../src/react/Components/'),
'#utils': path.resolve(__dirname, '../src/react/utils/'),
'#pages': path.resolve(__dirname, '../src/react/Pages/'),
'#constants': path.resolve(__dirname, '../src/react/Constants/'),
};
config.resolve.extensions.push('.ts', '.tsx');
return config;
},
framework: "#storybook/preact",
core: {
builder: "webpack5"
}
};
.vueStorybook/main.js
module.exports = {
stories: ['../src/vue/**/*.stories.#(js|jsx|ts|tsx)'],
addons: [
'#storybook/addon-links',
'#storybook/addon-essentials',
'#storybook/addon-interactions',
],
webpackFinal: async (config) => {
config.module.rules.push({
test: /\.(ts|tsx)$/,
use: [
{
loader: 'babel-loader',
options: {
presets: ['#babel/preset-env', { loose: true }],
plugins: [
['#babel/plugin-proposal-private-methods', { loose: true }]
['#babel/plugin-proposal-private-property-in-object', { loose: true }]
['#babel/plugin-proposal-class-properties', { loose: true }]
]
}
},
],
});
config.resolve.extensions.push('.ts', '.tsx');
return config;
},
framework: "#storybook/vue3",
core: {
builder: "webpack5"
}
};

wrangler dev failed using #cfworker/web

I'm trying to deploy a project on Cloudflare workers using wrangler. I'm using the #cfworker/web package for routing. I've only setup a route at / for testing but it doesn't seem to work.
Here's the dev output:
> wrangler dev
./node_modules/#cfworker/web/dist/application.js 31:30
Module parse failed: Unexpected token (31:30)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| }
| catch (err) {
> console.error(err?.stack ?? err);
| if (err instanceof HttpError) {
| return err.toResponse();
# ./node_modules/#cfworker/web/dist/index.js 3:0-33 3:0-33
# ./src/index.ts
Error: webpack returned an error. Try configuring `entry` in your webpack config relative to the current working directory, or setting `context = __dirname` in your webpack config.
my package.json:
{
"name": "my-project",
"main": "./src/index.ts",
"scripts": {
"dev": "wrangler dev",
"preview": "wrangler preview --watch",
"build": "wrangler build",
"publish": "wrangler publish"
},
"devDependencies": {
"#babel/cli": "^7.13.16",
"#babel/core": "^7.14.0",
"#babel/plugin-proposal-class-properties": "^7.13.0",
"#babel/plugin-proposal-nullish-coalescing-operator": "^7.16.5",
"#babel/plugin-proposal-optional-chaining": "^7.13.12",
"#babel/plugin-transform-runtime": "^7.13.15",
"#babel/preset-env": "^7.14.1",
"#babel/preset-typescript": "^7.13.0",
"#cloudflare/workers-types": "^2.2.2",
"babel-loader": "^8.2.2",
"typescript": "^4.2.4",
"webpack": "^5.36.2",
"webpack-cli": "^4.7.0"
},
"dependencies": {
"#cfworker/web": "^1.6.11"
}
}
my webpack.config.js:
const path = require('path')
module.exports = {
mode: 'production',
entry: './src/index.ts',
output: {
filename: 'worker.js',
path: path.join(__dirname, 'dist'),
},
performance: {
hints: false,
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
},
module: {
rules: [
{
test: /\.(ts|js)x?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
options: {
presets: [
'#babel/preset-env',
'#babel/preset-typescript',
],
plugins: [
'#babel/plugin-proposal-class-properties',
'#babel/plugin-transform-runtime',
'#babel/plugin-proposal-optional-chaining',
'#babel/plugin-proposal-nullish-coalescing-operator',
],
},
},
],
},
}
I can't figure out if there's something wrong with my webpack config or if there something else.
I managed to get it working by changing the webpack config at line
exclude: /(node_modules|bower_components)/,
to
include: /(node_modules\\#cfworker\\web|src)/,
It seems that the #cfworker/web module is using optional chaining and nullish coalescing and was excluded from the babel-loader.

Getting webpack error after update to version 5 from 3

I recently moved from webpack 3 to 5 and made some changes as per the suggestions, however after this upgrade, build fails and server won't start. here is my webpack file
const path = require('path')
const webpack = require('webpack')
const glob = require('glob')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const FileManagerPlugin = require('filemanager-webpack-plugin')
const libraryBaseStyles = glob.sync('./library/basics/**/styles.scss')
const libraryAllStyles = glob.sync('./library/**/styles.scss', {
ignore: ['./library/basics/**/styles.scss'],
})
const isProd = process.env.NODE_ENV === 'production'
let externals = []
let rules = []
let entries = {}
let pluginsBabel = ['transform-runtime', 'lodash']
let plugins = [
new ExtractTextPlugin({
// define where to save the file
filename: 'css/[name].css',
allChunks: true,
}),
]
let output = {
path: path.resolve(__dirname, isProd ? './dist' : './public'),
filename: 'js/[name].js',
}
if (isProd) {
plugins.push(
new OptimizeCssAssetsPlugin({
assetNameRegExp: /index.css$/g,
cssProcessor: require("cssnano"),
cssProcessorOptions: {
discardComments: { removeAll: true },
autoprefixer: {
browsers: ["last 2 versions", "Safari > 8"],
add: true,
},
},
canPrint: true,
}),
new webpack.ContextReplacementPlugin(
/moment[\/\\]locale$/,
/(fr\.js|nl-be|nl\.js|en-gb|de\.js)/
),
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false,
}),
new FileManagerPlugin({
onEnd: {
copy: [
{ source: "dist/css/index.css", destination: "dist/css/index.scss" },
{ source: "public/fonts", destination: "dist/fonts" },
],
},
})
);
entries.index = libraryBaseStyles
.concat(libraryAllStyles)
.concat(['./library/index.js'])
// https://webpack.js.org/guides/author-libraries/
output.library = 'nmbs-redesign-website'
output.libraryTarget = 'umd'
externals = [
'autosize',
// 'babel-polyfill',
'gsap',
'hammerjs',
'imagesloaded',
'inputmask',
'masonry-layout',
'moment',
'packery',
'picturefill',
'pikaday',
'prismjs',
'promise-polyfill',
'scrollmonitor',
'whatwg-fetch',
'wicg-inert',
]
} else {
rules.push({
test: /\.svg$/,
include: path.join(__dirname, './library/basics/Icons'),
loaders: [
'svg-sprite-loader?' +
JSON.stringify({
name: 'icon-[name]',
prefixize: true,
}),
'svgo-loader?' +
JSON.stringify({
plugins: [
{removeTitle: true},
{convertPathData: false},
{removeUselessStrokeAndFill: true},
],
}),
],
})
plugins.push(new webpack.LoaderOptionsPlugin({options: {}}))
entries.library = libraryBaseStyles
.concat(libraryAllStyles)
.concat(['./library/index.js'])
entries.docs = glob.sync('./docs/**/styles.scss').concat(['./docs/index.js'])
}
rules.push(
{
test: /\.js$/,
// Default
// exclude: [path.resolve(__dirname, 'node_modules')],
// Specific
include: [
path.resolve(__dirname, 'library'),
path.resolve(__dirname, 'docs'),
path.resolve(__dirname, 'node_modules/dom7'),
path.resolve(__dirname, 'node_modules/ssr-window'),
path.resolve(__dirname, 'node_modules/swiper'),
],
loader: 'babel-loader',
query: {
plugins: pluginsBabel,
presets: [
[
'env',
{
targets: {
browsers: ['last 2 versions', 'Safari > 8'],
},
debug: true,
useBuiltIns: true,
},
],
'latest',
'stage-2',
],
},
},
// Loaders for other file types can go here
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{loader: 'css-loader', options: {url: false}},
{loader: 'sass-loader'},
],
}),
}
)
console.log('\nWebpack ' + process.env.NODE_ENV + '\n (isProd: ' + isProd + ')')
module.exports = {
entry: entries,
output: output,
externals: externals,
module: {
rules: rules,
},
plugins: plugins,
devtool: isProd ? "source-map" : "inline-source-map",
devServer: {
contentBase: path.join(__dirname, "public/"),
compress: true,
overlay: true,
inline: false,
port: 3000,
},
};
my Package.json
"name": "es6-library",
"version": "6.0.15",
"description": "Pattern Library",
"main": "dist/js/index.js",
"module": "library/index.js",
"scripts": {
"docs": "gulp watch:docs",
"nj": "gulp nunjucks",
"dev": "cross-env NODE_ENV=local webpack serve",
"build": "cross-env NODE_ENV=local ./node_modules/.bin/webpack && npm run versions",
"build-prod": "cross-env NODE_ENV=production ./node_modules/.bin/webpack && npm run versions",
"dist": "cross-env NODE_ENV=production ./node_modules/.bin/webpack && npm run versions",
"versions": "node -p \"process.env.npm_package_version\" > ./public/version-npm.txt && node -p \"require('moment')().format('MMM/DD/YYYY HH:mm')\" > ./public/version.txt",
"optimizesvg": "find ./library/basics/Icons -name '*.svg' -exec ./node_modules/.bin/svgo {} \\;",
"build-push-staging": "npm run build && git add . && git commit -m \"build `date +\"%d/%m/%Y\"`\" && git push",
"build-push-test": "npm run build && git add . && git commit -m \"require('moment')().format('MMM/DD/YYYY')\" && git push origin origin/test",
"build-for-release": "npm run build-prod && npm run dist && git add . && git commit -m \"compile dist \"require('moment')().format('MMM/DD/YYYY')\"",
"build-for-Deploy": "npm run build && git add . && git commit -m \"build \"require('moment')().format('MMM/DD/YYYY')\"",
"build-push-production": "npm run build-for-Deploy && git push",
"dist-push-production": "npm run build-for-release && git push && npm publish"
},
"author": "Amit",
"license": "ISC",
"dependencies": {
"autosize": "^4.0.2",
"babel-polyfill": "^6.26.0",
"fuse.js": "^6.4.6",
"gsap": "^3.6.1",
"hammerjs": "^2.0.8",
"imagesloaded": "^4.1.4",
"inputmask": "4.0.9",
"masonry-layout": "^4.2.2",
"moment": "^2.26.0",
"node-sass": "^5.0.0",
"packery": "^2.1.2",
"picturefill": "^3.0",
"prismjs": "^1.15.0",
"promise-polyfill": "^8.0",
"scrollmonitor": "^1.2",
"swiper": "^4.4.1",
"whatwg-fetch": "^2.0.4",
"wicg-inert": "^2.0"
},
"devDependencies": {
"babel-cli": "^6.18.0",
"babel-core": "^6.26.3",
"babel-eslint": "^6.0.4",
"babel-loader": "^7.1.5",
"babel-plugin-lodash": "^3.3.4",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-polyfill": "^6.8.0",
"babel-preset-env": "^1.6.1",
"babel-preset-latest": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"babel-register": "^6.26.0",
"cross-env": "^7.0.3",
"css-loader": "^5.2.4",
"cssnano": "^5.0.2",
"eslint": "^4.19.1",
"extract-text-webpack-plugin": "^3.0.2",
"file-loader": "^1.1.11",
"filemanager-webpack-plugin": "^4.0.0",
"glob": "^7.1.3",
"gulp": "^3.9.1",
"gulp-nunjucks-render": "git+https://github.com/carlosl/gulp-nunjucks-render.git",
"gulp-plumber": "^1.2.0",
"optimize-css-assets-webpack-plugin": "^3.2.0",
"sass-loader": "6.0.7",
"style-loader": "^0.21.0",
"svg-sprite-loader": "0.3.1",
"svgo": "^1.1.1",
"svgo-loader": "^2.2.0",
"webpack": "^5.36.2",
"webpack-cli": "^4.6.0",
"webpack-dev-server": "^3.11.2"
}
}
this is the error i am getting when i try to start the server(npm run dev)
Webpack local
(isProd: false)
[webpack-cli] Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
configuration.module.rules[2] should be one of these:
["..." | object { compiler?, dependency?, descriptionData?, enforce?, exclude?, generator?, include?, issuer?, issuerLayer?, layer?, loader?,
mimetype?, oneOf?, options?, parser?, realResource?, resolve?, resource?, resourceFragment?, resourceQuery?, rules?, sideEffects?, test?, type?,
use? }, ...]
-> A rule.
Details:
configuration.module.rules[2].loader should be a non-empty string.
-> A loader request.

You are running the esm-bundler build of Vue. It is recommended to configure your bundler

I am getting this error on my Vue 3 project:
You are running the esm-bundler build of Vue. It is recommended to configure your bundler to explicitly replace feature flag globals with boolean literals to get proper tree-shaking in the final bundle. See http://link.vuejs.org/feature-flags for more details.
webpack.mix.js
const mix = require ('laravel-mix');
const path = require ('path');
mix.webpackConfig ({
output: {
chunkFilename: 'js/chunks/[name].[chunkhash].js'
},
module: {
rules: [
{
test: /node_modules(?:\/|\\).+\.js$/,
loader: 'babel-loader',
options: {
presets: [['#babel/preset-env', {targets: 'last 2 versions, ie >= 10'}]],
plugins: ['#babel/plugin-transform-destructuring', '#babel/plugin-proposal-object-rest-spread', '#babel/plugin-transform-template-literals'],
babelrc: false
}
},
{
enforce: 'pre',
test: /\.(js|vue)$/,
loader: 'eslint-loader',
exclude: /node_modules/
}
]
},
resolve: {
alias: {
vue: "vue/dist/vue.esm-bundler.js"
},
},
optimization: {
providedExports: false,
sideEffects: false,
usedExports: false
}
});
mix.js ("resources/js/entry-point.js", "public/js").vue({})
.postCss ("resources/css/app.css", "public/css", [
require ("tailwindcss"),
]);
mix.extract (['vue']);
if (mix.inProduction ()) {
mix
.version ();
}
In this case, it does not matter whether I set mix.webpackConfig or not.
This is package.json:
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "mix",
"watch": "mix watch",
"watch-poll": "mix watch -- --watch-options-poll=1000",
"hot": "mix watch --hot",
"prod": "npm run production",
"production": "mix --production"
},
"devDependencies": {
"#vue/compiler-sfc": "^3.0.5",
"autoprefixer": "^10.2.4",
"axios": "^0.21",
"cross-env": "^5.1",
"css-loader": "^5.0.2",
"eslint-plugin-vue": "^7.5.0",
"file-loader": "^6.2.0",
"laravel-mix": "^6.0.6",
"mini-css-extract-plugin": "^1.3.6",
"postcss": "^8.2.6",
"resolve-url-loader": "^3.1.2",
"tailwindcss": "^2.0.3",
"url-loader": "^4.0.0",
"vue-loader": "^16.1.2",
"babel-eslint": "^10.1.0",
"eslint": "^7.19.0",
"eslint-config-google": "^0.14.0",
"eslint-loader": "^4.0.2"
},
"dependencies": {
"vue": "^3.0.5",
"vue-router": "4.0.3"
}
}
I read the provided link, but I did not see a way to solve this issue.
The linked docs specify two configurable flags:
__VUE_OPTIONS_API__ (enable/disable Options API support, default: true)
__VUE_PROD_DEVTOOLS__ (enable/disable devtools support in production, default: false)
For Webpack, use the DefinePlugin to set these flags:
const webpack = require('webpack')
mix.webpackConfig ({
plugins: [
new webpack.DefinePlugin({
__VUE_OPTIONS_API__: false,
__VUE_PROD_DEVTOOLS__: false,
}),
],
})
webpack.config.js
const Webpack = require('webpack');
module.exports = (env, options) => {
return {
...,
module : {
...,
},
plugins : [
...,
new Webpack.DefinePlugin({ __VUE_OPTIONS_API__: true, __VUE_PROD_DEVTOOLS__: true }), // to remove warn in browser console: runtime-core.esm-bundler.js:3607 Feature flags __VUE_OPTIONS_API__, __VUE_PROD_DEVTOOLS__ are not explicitly defined...
...,
],
...,
};
};
Or alternative is to add 2 lines into app entry file:
globalThis.__VUE_OPTIONS_API__ = true;
globalThis.__VUE_PROD_DEVTOOLS__ = false;
For laravel-mix use
mix.webpackConfig(webpack => {
return {
plugins: [
new webpack.DefinePlugin({
__VUE_OPTIONS_API__: false,
__VUE_PROD_DEVTOOLS__: false,
}),
],
}
})
For Laravel 8 add .vue().
https://laravel.com/docs/8.x/mix#vue
Mix will automatically install the Babel plugins necessary for Vue single-file component compilation support when using the vue method. No further configuration is required
mix.js('resources/js/app.js', 'public/js')
.postCss('resources/css/app.css', 'public/css', [
//
])
.vue();

Vue JS: Build command `npm run build` is not able to generate `index.html`

When I'm running npm run build, it is not creating index.html in the dist/ directory. The reason I need index.html is that I want to deploy my Vue project to AWS EC2 (/var/www/html/). What to do to generate this index.html?
My dist/ directory structure after running npm run build:
My package.json:
{
"name": "proto",
"description": "Prototype",
"version": "1.0.0",
"license": "MIT",
"private": true,
"scripts": {
"dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot",
"build": "cross-env NODE_ENV=production webpack --progress --hide-modules"
},
"dependencies": {
"#melmacaluso/vue-modal": "^2.1.0",
"firebase": "^7.14.2",
"fusioncharts": "^3.15.1-sr.1",
"vue": "^2.5.11",
"vue-fusioncharts": "^3.0.4",
"vue-router": "^3.1.6",
"vuex": "^3.3.0"
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
],
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.0",
"babel-preset-stage-3": "^6.24.1",
"cross-env": "^5.0.5",
"css-loader": "^0.28.7",
"file-loader": "^1.1.4",
"vue-loader": "^13.0.5",
"vue-template-compiler": "^2.4.4",
"webpack": "^3.6.0",
"webpack-dev-server": "^2.9.1"
}
}
My webpack.config.js:
var path = require('path')
var webpack = require('webpack')
module.exports = {
entry: './src/main.js',
output: {
path: path.resolve(__dirname, './dist'),
publicPath: '/dist/',
filename: 'build.js'
},
module: {
rules: [
{
test: /\.css$/,
use: [
'vue-style-loader',
'css-loader'
],
}, {
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
}
// other vue-loader options go here
}
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]?[hash]'
}
}
]
},
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js'
},
extensions: ['*', '.js', '.vue', '.json']
},
devServer: {
historyApiFallback: true,
noInfo: true,
overlay: true
},
performance: {
hints: false
},
devtool: '#eval-source-map'
}
if (process.env.NODE_ENV === 'production') {
module.exports.devtool = '#source-map'
// http://vue-loader.vuejs.org/en/workflow/production.html
module.exports.plugins = (module.exports.plugins || []).concat([
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
}),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
compress: {
warnings: false
}
}),
new webpack.LoaderOptionsPlugin({
minimize: true
})
])
}
The build command output:
$ npm run build
> proto#1.0.0 build C:\Users\john\Documents\VUE\dummy_prototype_1
> cross-env NODE_ENV=production webpack --progress --hide-modules
In your webpack.config.js, scroll down then add the HtmlWebpackPlugin plugin into module.exports.plugins as #Michal Levy suggested.
Updated:
For the error (webpack.js:348 throw err; TypeError: Cannot read property 'make' of undefined), one possible reason is version issue. The solution is downgrade (uninstall then install) html-webpack-plugin to 3.2.0.
Below is new configuration for plugins:
if (process.env.NODE_ENV === 'production') {
module.exports.devtool = '#source-map'
// http://vue-loader.vuejs.org/en/workflow/production.html
module.exports.plugins = (module.exports.plugins || []).concat([
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
}),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
compress: {
warnings: false
}
}),
// below is the plugin you need to add
new HtmlWebpackPlugin({
filename: path.resolve(__dirname, './dist/index.html'), // the path where is the `index.html` generated.
template: 'index.html',
inject: true,
minify: {
removeComments: true,
collapseWhitespace: true,
removeAttributeQuotes: true
},
}),
new webpack.LoaderOptionsPlugin({
minimize: true
})
])
}
Just use HtmlWebpackPlugin
It will automatically create (new or from template you provide) index.html in the dist folder and inject any necessary <script> (for js bundles) or <link> (for extracted CSS) tags
As it seems you already have index.html template, use template option - see the docs