Trying to compile Vue.js code using webpack - error - npm

So I am trying to compile some vue.js code using webpack, but when I try to run webpack from command prompt I get the following error:
ERROR in Cannot find module 'core-js/library/fn/symbol/iterator'.
I can't get my head around this error and I don't know if I'm missing any dependencies.
Please let me know if there's something that's not right.
Here's my webpack.config:
module.exports = {
// This is the "main" file which should include all other modules
entry: './view/vue/main.js',
// Where should the compiled file go?
output: {
path: './layout/standard/js',
filename: 'vue-build.js'
},
module: {
// Special compilation rules
loaders: [
{
test: /\.js$/,
loader: 'babel',
exclude: /node_modules/
},
{
test: /\.vue$/,
loader: 'vue'
}
]
},
vue: {
loaders: {
js: 'babel'
}
}
}
And package.json:
{
"author": "CDG",
"license": "ISC",
"private": true,
"scripts": {
"prod": "gulp -p | webpack -p",
"dev": "gulp watch | webpack --watch"
},
"dependencies": {
"vue": "^1.0.27",
"vue-clickaway": "^1.1.3",
"vue-resource": "^0.9.3",
"vue-socket.io": "^1.0.2",
"vue-spinner": "^1.0.2",
"vuex": "^1.0.0-rc.2"
},
"devDependencies": {
"babel-core": "^6.1.2",
"babel-loader": "^6.1.0",
"babel-plugin-transform-runtime": "^6.1.2",
"babel-preset-es2015": "^6.14.0",
"babel-preset-stage-0": "^6.1.2",
"babel-runtime": "^5.8.0",
"css-loader": "^0.23.0",
"style-loader": "^0.13.0",
"vue-html-loader": "^1.0.0",
"vue-loader": "^7.3.0",
"webpack": "^1.12.2"
}
}
And .babelrc:
{
"presets": ["es2015", "stage-0"],
"plugins": ["transform-runtime"]
}
Please help me with this problem, it's really bugging me.
Thank you!
EDIT:
I did manage to solve the issue running npm i core-js, but now I have the following error when typing webpack: ERROR in Cannot find module "./_baseClone", what am I missing?

Related

ERROR in Entry module not found: Error: Can't resolve './src' in 'C:\project\projekt'

I have been looking at different answers but its not working for me, when I try to run npm run start:dev on windows, I got this error:
ERROR in Entry module not found: Error: Can't resolve './src' in 'C:\project\projekt'
My package.json file is:
{
"name": "projekt",
"private": true,
"dependencies": {
"#rails/actioncable": "^6.0.0",
"#rails/activestorage": "^6.0.0",
"#rails/ujs": "^6.0.0",
"#rails/webpacker": "4.2.2",
"turbolinks": "^5.2.0",
"vue": "^2.6.11",
"vue-loader": "^15.8.3",
"vue-resource": "^1.5.1",
"vue-template-compiler": "^2.6.11",
"vue-turbolinks": "^2.0.4"
},
"scripts": {
"start:dev": "webpack-dev-server"
},
"version": "0.1.0",
"devDependencies": {
"webpack": "^4.41.5",
"webpack-dev-server": "^3.10.1"
}
}
My webpack.config.js file is:
var webpack = require('webpack');
module.exports = {
entry: __dirname + '/index.js',
output: {
path: __dirname + '/',
filename: 'specs.js'
},
module: {
loaders: [
{ test: /\.js$/, loader: 'buble-loader', exclude: /node_modules/ }
]
},
plugins: [new webpack.optimize.ModuleConcatenationPlugin()]
};

How to fix chunk load failure?

I am trying to make a web application using Vue and Monaco Editor for the frontend and Asp.Net Core 3 on the backend.
I am also using webpack since I'm using Vue single page components.
I am new to webpack, and don't understand all its functionality. Anyway, webpack splits the build into several files (chunks it seems). However, when loading the web page I keep getting the error Uncaught (in promise) ChunkLoadError: Loading chunk 2 failed.
I tried to googling the answer, but nothing I have done has worked so far.
Here are my package.json and webpack.config.json.
Package.json
{
"name": "parvis",
"version": "1.0.0",
"description": "This is a description",
"main": "main.js",
"scripts": {
"dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot",
"serve": "cross-env NODE_ENV=development webpack --devtool source-map --progress --hide-modules",
"build": "cross-env NODE_ENV=production webpack --progress --hide-modules"
},
"keywords": [
"dataflow"
],
"author": "Marin Aglić Čuvić",
"license": "MIT",
"dependencies": {
"bootstrap": "^4.3.1",
"bootstrap-vue": "^2.0.2",
"escodegen": "^1.12.0",
"filbert": "^0.1.20",
"lodash": "^4.17.15",
"monaco-editor": "^0.18.1",
"monaco-editor-webpack-plugin": "^1.7.0",
"vee-validate": "^3.0.8",
"vue": "^2.6.10",
"vue-monaco": "^1.1.0",
"vue-router": "^3.1.3"
},
"devDependencies": {
"#babel/core": "^7.6.2",
"#babel/preset-env": "^7.6.2",
"babel-loader": "^8.0.6",
"cross-env": "^6.0.3",
"css-loader": "^3.2.0",
"html-webpack-plugin": "^3.2.0",
"rimraf": "^3.0.0",
"uglifyjs-webpack-plugin": "^2.2.0",
"vue-loader": "^15.7.1",
"vue-style-loader": "^4.1.2",
"vue-template-compiler": "^2.6.10",
"webpack": "^4.41.0",
"webpack-cli": "^3.3.9",
"webpack-dev-server": "^3.8.2"
}
}
This is my webpack.config.js.
const path = require('path');
const webpack = require('webpack');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
module.exports = {
mode: process.env.NODE_ENV,
entry: {
main: './wwwroot/client/src/main.js',
// 'editor.worker': 'monaco-editor/esm/vs/editor/editor.worker.js'
},
output: {
globalObject: 'self',
path: path.resolve(__dirname, './wwwroot/vuebundles/'),
publicPath: '/wwwroot/vuebundles/',
filename: '[name].build.js',
chunkFilename: '[name].chunk.js'
},
module: {
rules: [
{
test: /\.css$/,
use: [
'vue-style-loader',
'css-loader'
],
}, {
test: /\.vue$/,
loader: 'vue-loader',
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]?[hash]'
}
},
]
},
plugins: [
new VueLoaderPlugin(),
new MonacoWebpackPlugin({
languages: ['javascript', 'csharp']
})
]
};
I understand similar questions have been posted in the past, but most of them have not been answered. Any solution I tried didn't work for me.
It took me an embarrassingly long time to figure out that my publicPath was wrong.
Probably because I didn't use it from webpack before it started creating chunks.
Anyway, the publicPath property should be:
publicPath: '/vuebundles/',
Without "wwwroot".

VUE CLI 3 - Testing Single-File Components with Mocha + webpack

I am trying to follow the documentation mentioned here Vue Test Utils.
Below is what I currently have set up.
Project setup: Vue CLI 3.2.1 with Node v8.11.2
devDependencies:
"#vue/cli-plugin-babel": "^3.2.0",
"#vue/cli-plugin-eslint": "^3.2.0",
"#vue/cli-service": "^3.2.0",
"#vue/test-utils": "^1.0.0-beta.28",
"babel-eslint": "^10.0.1",
"babel-plugin-istanbul": "^5.1.0",
"cross-env": "^5.2.0",
"eslint": "^5.8.0",
"eslint-config-standard": "^12.0.0",
"eslint-loader": "^2.1.1",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-node": "^8.0.0",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"eslint-plugin-vue": "^5.0.0-0",
"expect": "^24.0.0",
"istanbul-instrumenter-loader": "^3.0.1",
"jsdom": "^13.2.0",
"jsdom-global": "^3.0.2",
"mocha": "^5.2.0",
"mocha-webpack": "^1.1.0",
"node-sass": "^4.10.0",
"nyc": "^13.1.0",
"sass-loader": "^7.1.0",
"vue-template-compiler": "^2.5.17",
"webpack-cli": "^3.2.1",
"webpack-node-externals": "^1.7.2"
And nyc config inside package.json also:
"nyc": {
"include": [
"src/**/*.(js|vue)"
],
"instrument": false,
"sourceMap": false
},
vue.config.js:
const nodeExternals = require('webpack-node-externals')
const path = require('path')
let isCoverage = process.env.NODE_ENV === 'coverage';
module.exports = {
mode: 'development',
externals: [nodeExternals()],
devtool: 'inline-cheap-module-source-map',
output: {
// use absolute paths in sourcemaps (important for debugging via IDE)
devtoolModuleFilenameTemplate: '[absolute-resource-path]',
devtoolFallbackModuleFilenameTemplate: '[absolute-resource-path]?[hash]'
},
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
}
].concat(
isCoverage ? {
test: /\.(js|ts)/,
include: path.resolve('src'),
loader: 'istanbul-instrumenter-loader',
options: { esModules: true }
}: [],
{
test: /.js$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
},
{
test: /\.ts$/,
exclude: /(node_modules|bower_components)/,
loader: 'ts-loader'
}
)
},
target: 'node',
externals: [nodeExternals()],
devtool: "inline-cheap-module-source-map"
}
My test folder structure looks like this:
My test code looks like this:
So far I tried running these commands:
"test-ci": "mocha-webpack --webpack-config vue.config.js --require test/setup.js test/**/*.js"
"cover": "cross-env NODE_ENV=coverage nyc --reporter=lcov --reporter=text npm run test-ci"
If I run test-ci it will output this: WEBPACK Compiled successfully in 631ms
But it is just a blank page after if I ran cover, then the output comes out as nothing being log by nyc:
What am I doing wrong here?
I was facing the same issue and including vue and js files separately fixed it for me.
"nyc": {
"include": [
"src/**/*.js",
"src/**/*.vue"
],
"instrument": false,
"sourceMap": false
},
Despite using node v10.16.0 and vue-cli 3.11.0, I faced the same problem here. Mohit's answer didn't worked, but the following syntax did:
// package.json
"nyc": {
"extension": [
".js",
".vue"
]
},

How to resolve "Cannot resolve 'file'" error in webpack?

I keep getting this really annoying error in webpack and even when I run webpack --display-error-details, I get no errors. But anytime I run webpack-dev-server I get the following error. I really can't see where I am going wrong in my configuration.
Entry module not found: Error: Cannot resolve 'file' or 'directory'
./frontend/app.jsx
module.exports = {
context: __dirname,
entry: './frontend/app.jsx',
output: {
filename: 'bundle.js',
path: __dirname
},
module: {
loaders: [
{
test: [ /\.js$/, /\.jsx$/],
exclude: /(node_modules)/,
loader: 'babel-loader',
query: {
presets: ['es2015', 'react']
}
},
{
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'sass-loader']
}
]
},
devtool: 'source-map',
resolve: {
extensions: ['.js', '.jsx', '.scss' ]
}
};
{
"name": "basicapp",
"version": "1.0.0",
"description": "",
"main": "app.jsx",
"author": "",
"license": "ISC",
"scripts": {
"start": "webpack-dev-server --env development",
"dev-server": "nodemon ./server.js localhost 8080",
"build": "webpack --env production"
},
"dependencies": {
"babel-cli": "^6.24.0",
"babel-core": "^6.24.0",
"babel-loader": "^6.4.1",
"babel-preset-es2015": "^6.24.0",
"babel-preset-react": "^6.23.0",
"css-loader": "^0.27.3",
"express": "^4.15.2",
"express-graphql": "^0.6.3",
"lodash": "^4.17.4",
"node-sass": "^4.5.1",
"react": "^15.4.2",
"react-dom": "^15.4.2",
"react-redux": "^5.0.3",
"react-router": "^4.0.0",
"redux": "^3.6.0",
"sass-loader": "^6.0.3",
"webpack": "^2.3.2"
},
"devDependencies": {
"html-webpack-plugin": "^2.28.0",
"node-sass": "^4.5.1",
"nodemon": "^1.11.0",
"sass-loader": "^6.0.3"
}
}
Webpack may not be treating __dirname as you want it to and may be resolving it to / instead. Try adding this to your webpack config:
{
node: {
__dirname: true
}
}
this can be because of multiple reasons the best way to identify the exact issue is to tryout the below two commands:
if you are running webpack 1/2 alone then use the snippet:
webpack --display-error-details
if you are running the webpack dev server then use the snippet:
webpack-dev-server --display-error-details
this would provide a detailed error report in the console

Bundle File size trouble with webPack

In my react app,on first time i was working with "browserify" for compile de es6 files to es5. But when i check the bundle file has a size for 1.3mb (so much) when my folder with all scripts have 200kb. I think, probably that browserify was including multiples times the same scripts. That is because I have (for example) "Config.js" and I include it on any file that I need
with
import Config from .'/config.js';
If i don't do that, the app shows errors saying that request that variable in that section. Then i change my manage from browserify to webpack. I road about this, because everything is new for me, and the docs say that webpack read my dependencies and try to include once any file. But my bundle file keep sizing 1.3mb.
This is my dummy webpack.config.js
var path = require('path');
var webpack = require('webpack');
module.exports = {
entry: './js/src/index.js',
output: { path: __dirname, filename: 'bundle.js' },
module: {
loaders: [
{
test: /.jsx?$/,
loader: 'babel-loader',
exclude: /node_modules|libs/, //npm and bower_components(libs)
query: {
presets: ['es2015', 'react']
}
}
]
},
};
This is my package.json, there you can see the browserify command that i was executing before try with webpack (The start command).
{
"name": "appname",
"version": "1.0.0",
"description": "app description",
"main": "js/dist/index.js",
"dependencies": {
"babelify": "^7.3.0",
"browserify": "^13.1.1",
"fetch": "^1.1.0",
"owl.carousel": "^2.2.0",
"react": "^15.4.2",
"react-dom": "^15.4.2",
"react-image-holder": "^2.0.1",
"react-owl-carousel": "^0.14.0",
"react-toastr": "^2.8.2",
"whatwg-fetch": "^2.0.1"
},
"devDependencies": {
"babel": "^6.5.2",
"babel-cli": "^6.18.0",
"babel-core": "^6.22.1",
"babel-loader": "^6.2.10",
"babel-plugin-external-helpers": "^6.18.0",
"babel-plugin-transform-react-jsx": "^6.8.0",
"babel-preset-env": "^1.1.5",
"babel-preset-es2015": "^6.22.0",
"babel-preset-es2017": "^6.16.0",
"babel-preset-latest": "^6.16.0",
"babel-preset-react": "^6.22.0",
"babelify": "^7.3.0",
"browserify": "^13.3.0",
"envify": "^4.0.0",
"gulp": "^3.9.1",
"gulp-concat": "^2.6.1",
"gulp-concat-css": "^2.3.0",
"gulp-notify": "^3.0.0",
"gulp-uglify": "^2.0.1",
"gulp-uglifycss": "^1.0.6",
"jquery": "^3.1.1",
"jquery-ui": "^1.12.1",
"react": "^15.4.2",
"react-dom": "^15.4.2",
"react-redux": "^5.0.1",
"react-router": "^3.0.0",
"react-router-redux": "^4.0.7",
"redux": "^3.6.0",
"uglify": "^0.1.5",
"watchify": "^3.8.0",
"webpack": "^1.14.0",
"whatwg-fetch": "^2.0.1"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"watch-js": "NODE_ENV=production watchify assets/js/main.js -t babelify -t bulkify -o dist/js/app.js -v --full-path=false",
"start": "set NODE_ENV=production && watchify js/src/index.js -v -t [babelify --presets [env] ] -o js/dist/index.js",
"build": "browserify js/src/index.js -g [envify --NODE_ENV 'production'] -t [ babelify --presets [env] ] -t > js/dist/app.js"
},
"keywords": [
"app",
"jidapp"
]
You can try specifying the devtool setting within your webpack.config.js.
Here is some info on what the different settings do. https://webpack.js.org/configuration/devtool/
For production builds I typically use cheap-module-source-map. In development, I use eval.
var path = require('path');
var webpack = require('webpack');
module.exports = {
devtool: 'cheap-module-source-map',
entry: './js/src/index.js',
output: { path: __dirname, filename: 'bundle.js' },
module: {
loaders: [
{
test: /.jsx?$/,
loader: 'babel-loader',
exclude: /node_modules|libs/,
query: {
presets: ['es2015', 'react']
}
}
]
},
};
You can also look into other webpack optimization plugins here. https://github.com/webpack/docs/wiki/optimization