Vue-cli 3 - Webpack 4: cannot load images with .webp format using the image-webpack-loader - vue.js

I am trying to load images in Vue components with the extension .webp
<v-parallax :src="require('#/assets/images/hero.webp')">
I added the image-webpack-loader module
yarn add image-webpack-loader --dev
vue.config.js
const webpack = require('webpack')
module.exports = {
configureWebpack: {
module: {
rules: [
{
test: /\.(gif|png|jpe?g|svg)$/i,
use: [
'file-loader',
{
loader: 'image-webpack-loader',
options: {
webp: {
quality: 80
}
}
}
]
}
]
}
}
}
but I get an error in asset optimization during compilation
94% asset optimization
ERROR Failed to compile with 1 errors 18:57:32
error in ./src/assets/images/hero.webp
Module parse failed: Unexpected character '�' (1:4)
You may need an appropriate loader to handle this file type.
(Source code omitted for this binary file)
# ./node_modules/vue-loader/lib/template-compiler?{"id":"data-v-16f8e3e2","hasScoped":true,"optionsId":"0","buble":{"transforms":{}}}!./node_modules/
vue-loader/lib/selector.js?type=template&index=0!./src/components/Home/Heading.vue 11:24-60
# ./src/components/Home/Heading.vue
# ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"/Users/yves/Developments/myprojects/node_modules/.cac
he/cache-loader"}!./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/views/Home.vue
# ./src/views/Home.vue
# ./src/router.js
# ./src/main.js
# multi (webpack)-dev-server/client/index.js (webpack)/hot/dev-server.js ./src/main.js
what's wrong with my webpack settings ?

change test .. to
test: /.(gif|png|jpe?g|webp|svg)$/i,
and here we rae

Related

how to use react-monaco-editor together with worker-loader?

Describe the bug
react-monaco-editor cannot be used together with worker-loader.
To Reproduce
create a new typescript app with CRA, run a min react-monaco-editor demo. (everything is fine)
install worker loader and add config in config-overrides.js, and start app.
example repo to reproduce
ERROR in ./node_modules/monaco-editor/esm/vs/editor/editor.worker.js
Module build failed (from ./node_modules/worker-loader/dist/cjs.js):
TypeError: Cannot read properties of undefined (reading 'replace')
at getDefaultChunkFilename (/Users//Documents/test/my-project/node_modules/worker-loader/dist/utils.js:23:24)
at Object.pitch (/Users//Documents/test/my-project/node_modules/worker-loader/dist/index.js:61:108)
Child vs/editor/editor compiled with 1 error
assets by status 1.27 KiB [cached] 1 asset
./node_modules/monaco-editor/esm/vs/language/json/json.worker.js 39 bytes [not cacheable] [built] [1 error]
ERROR in ./node_modules/monaco-editor/esm/vs/language/json/json.worker.js
Module build failed (from ./node_modules/worker-loader/dist/cjs.js):
TypeError: Cannot read properties of undefined (reading 'replace')
at getDefaultChunkFilename (/Users//Documents/test/my-project/node_modules/worker-loader/dist/utils.js:23:24)
at Object.pitch (/Users//Documents/test/my-project/node_modules/worker-loader/dist/index.js:61:108)
Child vs/language/json/jsonWorker compiled with 1 error
details of my config-overrides.js
const webpack = require('webpack');
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
module.exports = function override(config, env) {
config.plugins.push(
new MonacoWebpackPlugin({
languages: ['json']
})
);
config.stats = {
children: true
}
config.module.rules.push(
{
test: /\.worker\.js$/,
use: {
loader: 'worker-loader',
options: {
inline: 'fallback',
filename: '[contenthash].worker.js',
},
},
},
{
test: /\.worker\.ts$/,
use: [
{
loader: 'worker-loader',
options: {
inline: 'fallback',
filename: '[contenthash].worker.js',
},
},
'ts-loader',
],
},
);
return config;
};
Environment (please complete the following information):
OS: MacOS
Browser Chrome
Bundler webpack5 (CRA)
[ ] I will try to send a pull request to fix this issue.
I have solved it. It seems not to be a problem of react-monaco-editor or monaco-editor.
The problem is between worker-loader and monaco-editor-webpack-plugin.
I temporarily update my worker-loader config to match workers in my src folder only and solve this problem.
It could be better to figure out how to configure it in monaco-editor-webpack-plugin because it build files contains worker from monaco-editor without hashcode.

You may need an appropriate loader to handle this file type. it does not allow html inside node_modules

i am using simple vue project and i added a aditional package called vue add electron-builder, my goal is to trigger server.js file whenever i open my electron app. i am having pouchdb express inside server.js file.i called server.js inside backround.js.i know i am facing error due to babel but i dont't know how to configure in my project.
vue.config.js
module.exports = {
pluginOptions: {
electronBuilder: {
builderOptions: {
win: {
icon: './public/icon.ico'
}
}
}
}
}
babel.config.js
module.exports = {
sourceType: 'unambiguous',
presets: [
'#vue/cli-plugin-babel/preset'
],
ignore: [
'src/entities/*'
]
}
i am facing error
ERROR Failed to compile with 1 errors 7:50:46 PM
error in **./node_modules/pouchdb-fauxton/www/index.html**<---this file is not allowing
Module parse failed: Unexpected token (1:0)
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
> <!doctype html>
| <html lang="en">
| <head>
# ./node_modules/express-pouchdb/lib/routes/fauxton.js 7:32-66
# ./node_modules/express-pouchdb/lib sync ^\.\/.*$
# ./node_modules/express-pouchdb/lib/index.js
# ./backend_db/server.js
# ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/vuetify-loader/lib/loader.js??ref--18-0!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/App.vue?vue&type=script&lang=js&
# ./src/App.vue?vue&type=script&lang=js&
# ./src/App.vue
# ./src/main.js
# multi (webpack)-dev-server/client?http://localhost:8080/sockjs-node (webpack)/hot/dev-server.js ./src/main.js
I think the error message is pretty self explanatory: you need to add the webpack loader for html files.
npm install --save-dev html-loader
Then in vue.config.js:
module.exports = {
chainWebpack: config => {
config.module
.rule('html')
.test(/\.html$/)
.use('html-loader')
.loader('html-loader')
}
}

Tests fail to run on React Native

My babel.config.js is:
module.exports = {
presets: [
'module:metro-react-native-babel-preset'
]
};
When I run npm test I get:
Test suite failed to run
[BABEL] unknown: Preset /* your preset / requires a filename to be set when babel is called directly,
babel.transform(code, { filename: 'file.ts', presets: [/ your preset */] });
See https://babeljs.io/docs/en/options#filename for more information.
If I change config file to:
module.exports = {
presets: [
'react-native'
]
}
then all tests run.
My question: can I change it? What is the difference between both?
Thank you!

Module not found after adding lang="less" to style tag in component.vue

My question is similar to this one but I do not understand the answer there:
Webpack Less-Loader with Style-Loader not injecting <style> tag
I don't have the "reputation" to comment, so I will ask a new question.
I do not want to include my .less fine in my .js, I simply want to use LessCSS notation in the tag in my layout, template, page and components.
I have installed the less loader:
$npm install --save-dev less-loader
I have added the following to my quasar.conf.js file:
extendWebpack (cfg) {
/* EXISTING
cfg.module.rules.push({
enforce: 'pre',
test: /\.(js|vue)$/,
loader: 'eslint-loader',
exclude: /node_modules/
})
*/
// NEW
cfg.module.rules.push({
test: /\.less$/,
use: [
'vue-style-loader',
'css-loader',
'less-loader'
]
})
}
And as soon as I add " lang='less'" to my style tag of my component (LoadingOverlay.vue):
<style lang="less">
</style>
I get the following error when running quasar dev:
ERROR Failed to compile with 1 errors 12:02:54
error in ./src/components/global/LoadingOverlay.vue?vue&type=style&index=0&lang=less&
Module build failed (from ./node_modules/less-loader/dist/cjs.js):
// load the styles
var content = require("!!../../../node_modules/css-loader/index.js!../../../node_modules/less-loader/dist/cjs.js!../../../node_modules/vue-loader/lib/index.js??vue-loader-options!./LoadingOverlay.vue?vue&type=style&index=0&lang=less&");
^
Unrecognised input
in C:\wamp\www\plenty-mobile\src\components\global\LoadingOverlay.vue?vue&type=style&index=0&lang=less& (line 4, column 12)
# ./node_modules/vue-style-loader??ref--9-oneOf-2-0!./node_modules/css-loader??ref--9-oneOf-2-1!./node_modules/vue-loader/lib/loaders/stylePostLoader.js!./node_modules/postcss-loader/src??ref--9-oneOf-2-2!./node_modules/less-loader/dist/cjs.js??ref--9-oneOf-2-3!./node_modules/vue-style-loader!./node_modules/css-loader!./node_modules/less-loader/dist/cjs.js!./node_modules/vue-loader/lib??vue-loader-options!./src/components/global/LoadingOverlay.vue?vue&type=style&index=0&lang=less& 4:14-539 14:3-18:5 15:22-547
# ./src/components/global/LoadingOverlay.vue?vue&type=style&index=0&lang=less&
# ./src/components/global/LoadingOverlay.vue
# ./node_modules/babel-loader/lib??ref--1-0!./node_modules/vue-loader/lib??vue-loader-options!./src/layouts/default.vue?vue&type=script&lang=js&
# ./src/layouts/default.vue?vue&type=script&lang=js&
# ./src/layouts/default.vue
# ./src/router/routes.js
# ./src/router/index.js
# ./.quasar/app.js
# ./.quasar/client-entry.js
# multi (webpack)-dev-server/client?http://0.0.0.0:8080 (webpack)/hot/dev-server.js ./.quasar/client-entry.js
Any help very much appreciated - thanks
I have followed the docs and tried the above but am limited as I am pretty new to quasar framework and vueJS
I simply expect to be able to use lessCSS notation in my tags in templates, layouts, pages and components

graphql-tag/loader: Module build failed with GraphQLError: Syntax Error

Weird issue I am facing. Using Vue-CLI3 npm run serve.
Have the following config:
// vue.config.js
module.exports = {
chainWebpack: config => {
// GraphQL Loader
config.module
.rule('graphql')
.test(/\.graphql$/)
.use('graphql-tag/loader')
.loader('graphql-tag/loader')
.end();
}
};
and one single .graphql file:
mutation AddOfficeMutation(
$name: String
$location: String
) {
createOffice(
input: {office: { name: $name, location: $location }}
) {
office {
id
name
location
}
}
}
when running npm run serve, I get the following error:
ERROR Failed to compile with 1 errors 1:11:08 PM
error in ./src/graphql/AddOfficeMutation.graphql
Module build failed (from ./node_modules/graphql-tag/loader.js):
GraphQLError: Syntax Error: Unexpected Name "var"
at syntaxError (/Users/danroc/Dropbox/projects/tal-firebase/client-vue/node_modules/graphql/error/syntaxError.js:24:10)
at unexpected (/Users/danroc/Dropbox/projects/tal-firebase/client-vue/node_modules/graphql/language/parser.js:1490:33)
at parseDefinition (/Users/danroc/Dropbox/projects/tal-firebase/client-vue/node_modules/graphql/language/parser.js:153:9)
at many (/Users/danroc/Dropbox/projects/tal-firebase/client-vue/node_modules/graphql/language/parser.js:1520:16)
at parseDocument (/Users/danroc/Dropbox/projects/tal-firebase/client-vue/node_modules/graphql/language/parser.js:113:18)
at parse (/Users/danroc/Dropbox/projects/tal-firebase/client-vue/node_modules/graphql/language/parser.js:48:10)
at parseDocument (/Users/danroc/Dropbox/projects/tal-firebase/client-vue/node_modules/graphql-tag/src/index.js:129:16)
at gql (/Users/danroc/Dropbox/projects/tal-firebase/client-vue/node_modules/graphql-tag/src/index.js:170:10)
at Object.module.exports (/Users/danroc/Dropbox/projects/tal-firebase/client-vue/node_modules/graphql-tag/loader.js:44:18)
# ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/AddOfficeForm.vue?vue&type=script&lang=js& 29:0-69 59:18-35
# ./src/components/AddOfficeForm.vue?vue&type=script&lang=js&
# ./src/components/AddOfficeForm.vue
# ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/views/AddOfficeView.vue?vue&type=script&lang=js&
# ./src/views/AddOfficeView.vue?vue&type=script&lang=js&
# ./src/views/AddOfficeView.vue
# ./src/router/routes.js
# ./src/router/router-config.js
# ./src/main.js
# multi ./node_modules/#vue/cli-service/node_modules/webpack-dev-server/client?http://192.168.0.99:8080/sockjs-node (webpack)/hot/dev-server.js ./src/main.js
Using:
"graphql": "^14.0.2"
"graphql-tag": "^2.10.0"
I am slowly assuming this might be an error with my Babel or Vue config?
Anyone can shed some light on this?
Thanks!
I faced the same issue and it seemed that having 2 loaders make the crash.
I had installed graphql-tag and webpack-graphql-loader .
Try to uninstall every package that includes apollo or graphql and reinstall using vue cli again. vue add apollo. It worked for me.