Use debian packaged node modules when available
 - Exclude packaged modules from transpiling
 - Remove webpack-bundle-analyzer
 - Resolve .json files
 - Add mkdirp 1.0 and loader-utils 2.0 to ensure compatibility for packaged
   modules (See #976310)
 - Use link protocol for modules with permission issues (which has a bin: entry
   in package.json) or dependencies. Use portal protocol only for modules that
   1. does not have any other dependency and 2. does not have a bin: entry
   See https://github.com/yarnpkg/berry/issues/2266
 - Even better, portal protocol tries to satisfy even devDependencies so avoid
   it
 - Modules with problems compression-webpack-plugin, copy-webpack-plugin,
   jszip, mkdirp, js-yaml, font-awesome, katex, cache-loader, webpack
 - babel-loader, cache-loader needs loader-utils 1.x and we already have 2.x and
   no compat patch
 - brace-expansion is a major version ahead in the archive
 - xterm build is broken (#980406)

--- a/config/webpack.config.js
+++ b/config/webpack.config.js
@@ -19,7 +19,6 @@
 const { ESBuildMinifyPlugin } = require('esbuild-loader');
 
 const webpack = require('webpack');
-const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
 const { StatsWriterPlugin } = require('webpack-stats-plugin');
 const WEBPACK_VERSION = require('webpack/package.json').version;
 const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
@@ -289,6 +288,8 @@
 
   entry: generateEntries,
 
+  externals: [ 'canvas'  ],
+
   output: {
     path: WEBPACK_OUTPUT_PATH,
     publicPath: WEBPACK_PUBLIC_PATH,
@@ -300,10 +301,15 @@
   },
 
   resolve: {
-    extensions: ['.js'],
+    extensions: ['.js', '.gql', '.graphql', '.json'],
+    modules: ['node_modules','/var/lib/gitlab/node_modules','/usr/share/gitlab/vendor/node_modules','/usr/share/gitlab/node_modules/mermaid/node_modules', '/usr/share/nodejs/markdown-it/node_modules/', '/usr/lib/nodejs', '/usr/share/nodejs'],
     alias,
   },
 
+  resolveLoader: {
+    modules: ['node_modules','/var/lib/gitlab/node_modules', '/usr/lib/nodejs','/usr/share/nodejs'],
+   },
+
   module: {
     strictExportPresence: true,
     rules: [
@@ -419,7 +425,7 @@
       },
       {
         test: /\.(eot|ttf|woff|woff2)$/,
-        include: /node_modules\/(katex\/dist\/fonts|monaco-editor)/,
+        include: /(node_modules\/monaco-editor|\/usr\/share\/fonts\/truetype\/katex)/,
         loader: 'file-loader',
         options: {
           name: '[name].[contenthash:8].[ext]',
@@ -840,6 +846,7 @@
 
   node: {
     fs: 'empty', // editorconfig requires 'fs'
+    Buffer: 'mock',
     setImmediate: false,
   },
 };
--- a/app/assets/javascripts/pdf/index.vue
+++ b/app/assets/javascripts/pdf/index.vue
@@ -3,7 +3,7 @@
 
 import Page from './page/index.vue';
 
-GlobalWorkerOptions.workerSrc = '/assets/webpack/pdfjs/pdf.worker.min.js';
+GlobalWorkerOptions.workerSrc = '/assets/webpack/pdfjs/pdf.worker.js';
 
 export default {
   components: { Page },
--- a/package.json
+++ b/package.json
@@ -49,8 +49,8 @@
   "dependencies": {
     "@_ueberdosis/prosemirror-tables": "^1.1.3",
     "@apollo/client": "^3.5.10",
-    "@babel/core": "^7.18.5",
-    "@babel/preset-env": "^7.18.2",
+    "@babel/core": "link:/usr/share/nodejs/@babel/core",
+    "@babel/preset-env": "link:/usr/share/nodejs/@babel/preset-env",
     "@codesandbox/sandpack-client": "^1.2.2",
     "@cubejs-client/core": "^0.31.0",
     "@gitlab/at.js": "1.5.7",
@@ -60,7 +60,7 @@
     "@gitlab/ui": "52.6.0",
     "@gitlab/visual-review-tools": "1.7.3",
     "@gitlab/web-ide": "0.0.1-dev-20221217175648",
-    "@rails/actioncable": "6.1.4-7",
+    "@rails/actioncable": "link:/usr/share/nodejs/@rails/actioncable",
     "@rails/ujs": "6.1.4-7",
     "@sourcegraph/code-host-integration": "0.0.84",
     "@tiptap/core": "^2.0.0-beta.182",