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.
I have an odd problem as of late. When I run rollup -cw, Rollup bundles my app with Rollup v2.2.0. Everything's fine.
rollup v2.2.0
bundles ./src/index.html → build...
[Browsersync] Access URLs:
----------------------------------
Local: http://localhost:8000
External: http://10.0.0.13:8000
----------------------------------
UI: http://localhost:3001
UI External: http://localhost:3001
----------------------------------
[Browsersync] Serving files from: build
[Browsersync] Watching files...
(!) Circular dependencies
src/apollo/client.js -> src/apollo/resolvers/index.js -> src/apollo/resolvers/Query.js -> src/router/router.js -> src/apollo/auth.js -> src/apollo/client.js
node_modules/d3-selection/src/selection/index.js -> node_modules/d3-selection/src/selection/select.js -> node_modules/d3-selection/src/selection/index.js
node_modules/d3-selection/src/selection/index.js -> node_modules/d3-selection/src/selection/selectAll.js -> node_modules/d3-selection/src/selection/index.js
...and 17 more
(!) Generated an empty chunk
index
created build in 30.8s
[2020-03-26 23:42:30] waiting for changes...
[Browsersync] Reloading Browsers...
[Browsersync] Reloading Browsers... (buffered 302 events)
But if I subsequently save a file, rollup will bundle the app with rollup v1.31.1
rollup v1.31.1
bundles ./src/index.html → build, build/nomodule...
bundles ./src/index.html → build, build/nomodule...
bundles ./src/index.html → build, build/nomodule...
bundles ./src/index.html → build...
[!] (plugin copy) Error: EEXIST: file already exists, mkdir 'build/assets/systemjs/dist'
Error: EEXIST: file already exists, mkdir 'build/assets/systemjs/dist'
[!] (plugin copy) Error: EEXIST: file already exists, mkdir 'build/assets/systemjs/dist'
Error: EEXIST: file already exists, mkdir 'build/assets/systemjs/dist'
[!] (plugin copy) Error: EEXIST: file already exists, mkdir 'build/assets/systemjs/dist'
Error: EEXIST: file already exists, mkdir 'build/assets/systemjs/dist'
[!] (plugin Rollup Core) Error: Could not load /path/to/the-app/node_modules/#material/mwc-fab/node_modules/#material/mwc-ripple/ripple-directive.js (imported by /path/to/the-app/node_modules/#material/mwc-fab/mwc-fab-base.js): ENOENT: no such file or directory, open '/path/to/the-app/node_modules/#material/mwc-fab/node_modules/#material/mwc-ripple/ripple-directive.js'
Error: Could not load /path/to/the-app/node_modules/#material/mwc-fab/node_modules/#material/mwc-ripple/ripple-directive.js (imported by /path/to/the-app/node_modules/#material/mwc-fab/mwc-fab-base.js): ENOENT: no such file or directory, open '/path/to/the-app/node_modules/#material/mwc-fab/node_modules/#material/mwc-ripple/ripple-directive.js'
(!) Circular dependencies
src/apollo/client.js -> src/apollo/resolvers/index.js -> src/apollo/resolvers/Query.js -> src/router/router.js -> src/apollo/auth.js -> src/apollo/client.js
node_modules/d3-selection/src/selection/index.js -> node_modules/d3-selection/src/selection/select.js -> node_modules/d3-selection/src/selection/index.js
node_modules/d3-selection/src/selection/index.js -> node_modules/d3-selection/src/selection/selectAll.js -> node_modules/d3-selection/src/selection/index.js
...and 17 more
(!) Generated an empty chunk
index
created build in 31s
[2020-03-26 23:44:09] waiting for changes...
[Browsersync] Reloading Browsers...
Note that this second build also builds the production version (nomodule)
I don't have rollup v1.31.1 installed in this repo
AFAICT I have no packages that require rollup v1.31.1
> npm ls rollup
the-app#0.1.0 /path/to/the-app
├─┬ #open-wc/demoing-storybook#1.13.8
│ └── rollup#1.32.1
├── UNMET PEER DEPENDENCY rollup#2.2.0
└─┬ rollup-plugin-workbox#5.0.1
└─┬ workbox-build#5.0.0
└── rollup#1.32.1
npm ERR! peer dep missing: rollup#^1.20.0, required by #rollup/plugin-alias#3.0.1
npm ERR! peer dep missing: rollup#^1.20.0, required by #rollup/plugin-beep#0.1.2
npm ERR! peer dep missing: rollup#^1.20.0, required by #rollup/plugin-commonjs#11.0.2
npm ERR! peer dep missing: rollup#^1.20.0, required by #rollup/plugin-json#4.0.2
npm ERR! peer dep missing: rollup#^1.20.0, required by #rollup/plugin-node-resolve#7.1.1
npm ERR! peer dep missing: rollup#^1.20.0, required by #rollup/plugin-replace#2.3.1
npm ERR! peer dep missing: rollup#^0.65.2 || ^1.0.0, required by rollup-plugin-minify-html-literals#1.2.3
npm ERR! peer dep missing: rollup#^1.4.1, required by rollup-plugin-notify#1.1.0
I don't have rollup installed globally, having run yarn global remove rollup and npm r -g rollup
Here's my rollup.config.js
import dotenv from 'dotenv';
import path from 'path';
import alias from '#rollup/plugin-alias';
import beep from '#rollup/plugin-beep';
import commonjs from '#rollup/plugin-commonjs';
import json from '#rollup/plugin-json';
import replace from '#rollup/plugin-replace';
import resolve from '#rollup/plugin-node-resolve';
import { generateSW } from 'rollup-plugin-workbox';
import { terser } from 'rollup-plugin-terser';
import babel from 'rollup-plugin-babel';
import browsersync from 'rollup-plugin-browsersync';
import copy from 'rollup-plugin-copy';
import graphql from '#kocal/rollup-plugin-graphql';
import html from '#open-wc/rollup-plugin-html';
import litcss from 'rollup-plugin-lit-css';
import minifyLitHtml from 'rollup-plugin-minify-html-literals';
import notify from 'rollup-plugin-notify';
import watchAssets from 'rollup-plugin-watch-assets';
dotenv.config();
const PROCESS_WATCHING =
!!(process.argv.some(arg => !!arg.match(/-c?w/)) || process.argv.includes('--watch'));
const production = !PROCESS_WATCHING && process.env.NODE_ENV === 'production';
const replaceConfig = {
...redacted
};
const targets = [
{ src: 'node_modules/systemjs/dist', dest: 'build/assets/systemjs' },
{ src: 'node_modules/#webcomponents', dest: 'build/assets' },
{ src: 'src/favicon.ico', dest: 'build' },
{ src: 'src/favicon.ico', dest: 'build' },
{ src: 'src/manifest.webmanifest', dest: 'build' },
{ src: 'src/assets', dest: 'build' },
{ src: 'src/components/shared.css', dest: 'build' },
{ src: 'src/index.html', dest: 'build' },
{ src: 'src/*.css', dest: 'build' },
];
const customResolver = resolve({
extensions: ['.js', '.json', '.html', '.graphql', '.css'],
dedupe: id => id.includes('lit'),
});
const entries = [{
find: /#(.*)\/(.*)\b/,
replacement: path.resolve(__dirname, 'src/$1/$2'),
}, {
find: /#(.*)\b/,
replacement: path.resolve(__dirname, 'src/$1'),
}];
const esmOutput = {
format: 'esm',
dir: 'build',
sourcemap: true,
};
const nomoduleOutput = {
format: 'system',
dir: 'build/nomodule',
sourcemap: true,
};
const productionOutput = [esmOutput, nomoduleOutput].map(output => ({
...output,
plugins: [
terser(),
minifyLitHtml(),
generateSW(require('./workbox-config.js')),
],
}));
export default {
input: './src/index.html',
output: production ? productionOutput : esmOutput,
watch: {
include: 'src/**',
clearScreen: false,
},
plugins: [
html({ minify: production }),
babel(),
graphql(),
json(),
litcss({ uglify: production }),
customResolver,
alias({ entries, customResolver }),
replace(replaceConfig),
commonjs({ sourceMap: false }),
copy({ targets, copyOnce: PROCESS_WATCHING }),
...PROCESS_WATCHING ? [
watchAssets({ assets: ['src/**/*.html', 'src/**/*.css'] }),
browsersync({
port: 8000,
server: 'build',
single: true,
watch: true,
watchOptions: {
awaitWriteFinish: {
ignoreInitial: true,
stabilityThreshold: 2000,
pollInterval: 100,
ignore: '/assets/**/*',
},
},
}),
] : [],
beep(),
notify(),
],
// Don't warn about `this` - typescript produces these.
onwarn(warning, warn) {
if (warning.code === 'THIS_IS_UNDEFINED') return;
warn(warning);
},
};
What I've Tried
I've tried downgrading to rollup 1.32
I've tried npm dedupe rollup
I've tried yarn global remove rollup
I've tried rm -rf node_modules ; rm package-lock.json ; npm i
I've tried commenting out these plugins:
watchAssets
browsersync
copy
beep
notify
html
I've tried adding this plugin:
{
name: 'sanity-check',
buildStart() {
if (production) console.log('HEY!!!! IT\'S PRODUCTION');
},
},
No logs appeared
No dice.
What is causing this double-build behaviour, and where is rollup 1.31.1 coming from?
Update
Grepping node_modules for 1.31.1 produced this result
$ rg "1\.31\.1" node_modules/#surma
node_modules/#surma/rollup-plugin-off-main-thread/package.json
55: "rollup": "1.31.1"
$ npx npm-why #surma/rollup-plugin-off-main-thread
npx: installed 4 in 1.141s
Who required #surma/rollup-plugin-off-main-thread:
my-pwa > rollup-plugin-workbox > workbox-build > #surma/rollup-plugin-off-main-thread#1.2.0
So perhaps this error is caused by #surma/rollup-plugin-off-main-thread's pinning rollup to a specific version.
What I don't understand is how that makes it possible for npm to reference two rollup bins
enter image description here
enter image description here
INFO Starting development server...
95% emitting CopyPlugin ERROR Failed to compile with 1 errors12:29:34
error in ./src/router.js
Module parse failed: Unexpected token (17:13)
You may need an appropriate loader to handle this file type.
| // which is lazy-loaded when the route is visited.
| component: function component() {
> return import(
| /* webpackChunkName: "about" */
| './views/About.vue');
# ./src/main.js 6:0-30 10:10-16
# multi (webpack)-dev-server/client?http://192.168.75.129:8080/sockjs-node (webpack)/hot/dev-server.js ./src/main.js
{ [Error: EACCES: permission denied, open '/home/dollarkiller/demo/testdemo/node_modules/.stats-serve.json']
errno: -13,
code: 'EACCES',
syscall: 'open',
path:
'/home/dollarkiller/demo/testdemo/node_modules/.stats-serve.json' }
My operating environment:
node v10.15.2
npm 6.6.0
vue cli 3.3.0
vue create verdemo
Bable Router Vuex stylus eslint
Report errors
Default default deployment does not report errors
NPM "create vue project" (with router) - server not starting
Here is the answer you want
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.
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