0
votes

I am using the ngx-monaco-editor component together with Angular 5. The monaco-editor is loading fine on localhost, but not on my dev-server.

Loading failed for the script with source “https://se-dnexec.cic.muc/assets/monaco/vs/loader.js”.

This is my webpack.common configuration (under plugins):

 new WriteFilePlugin(),
 new CopyWebpackPlugin([
    {
      from: 'src/assets',
      to: 'assets'
    },
    {
      from: 'src/meta'
    },
    {
      from: 'node_modules/ngx-monaco-editor/assets/monaco',
      to: 'assets/monaco/',
    }
  ],
    isProd ? {
      ignore: ['mock-data/**/*']
    } : undefined
  ),

In webpack.dev I am using the configuration from webpack.common.

When I run the application from localhost under assets I can see this. localhost_monaco

But when running from dev-server I see that the monaco folder is missing:

devserver_monaco

I am using:

  • copy-webpack-plugin: "^4.5.1",
  • write-file-webpack-plugin: "^4.2.0"
  • webpack: "^3.11.0",
  • webpack-dev-server: "~2.7.1",

I would expect that when I run the dev-server that under assets folder the monaco folder is also copied, but for some reason that is not the case. Maybe someone experienced the same problem and can help me. (If further info is needed I can provide it).

I tried the following solution: Does not copy files to actual output folder when webpack-dev-server is used

2

2 Answers

0
votes

I am using the ngx-monaco-editor component with Angular 5. I checked that the path is somehow wrong, locally it works but on the server it does not. So this is the solution I had to do:

In NgxMonacoEditorConfig I did the following:

baseUrl: './assets'
0
votes

If you're using nginx to serve your production distribution you need to override the assets path for monaco as follows:

server {

    server_name localhost;
    listen      80;
    root        /usr/share/nginx/html;
    index       index.html index.htm;

    location / {

        try_files $uri $uri/ /index.html =404;

    }

    location /assets/monaco/vs {

        root /usr/share/nginx/html;
        try_files $uri $uri/ /index.html;

    }

}

Hope this saves someone else 5 hours!