question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

does not go to the editor when clicked

See original GitHub issue

it shows errors but if you click in the browser it doesn’t go to the code editor

const path = require("path");
const webpack = require("webpack");
const HTMLwebpackPlugin = require("html-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const OptimizeCssAssetPlugin = require("optimize-css-assets-webpack-plugin");
const TerserWebpackPlugin = require("terser-webpack-plugin");
const ErrorOverlayPlugin = require("error-overlay-webpack-plugin");

const isDev = process.env.NODE_ENV === "development";
const isProd = !isDev;

const cssLoader = (extra) => {
  const loaders = [
    {
      loader: MiniCssExtractPlugin.loader,
      options: {
        hmr: isDev,
        reloadAll: true,
        publicPath: "../",
      },
    },
    {
      loader: "css-loader",
      options: {
        url: true,
      },
    },
  ];

  if (extra) {
    loaders.push(extra);
  }

  return loaders;
};

module.exports = {
  context: path.resolve(__dirname, "src"),
  mode: "development",
  entry: {
    index: "./index.js",
  },
  output: {
    filename: isDev ? `js/[name].js` : `js/[name].[contenthash:8].chunk.js`,
    path: path.resolve(__dirname, "build"),
  },
  devServer: {
    port: 4200,
    hot: isDev,
  },

  optimization: {
    moduleIds: "hashed",
    splitChunks: {
      chunks: "all",
      name: false,
    },
    minimizer: [].concat(
      isProd
        ? [
            new OptimizeCssAssetPlugin(),
            new TerserWebpackPlugin(),
          ]
        : []
    ),
  },
  resolve: {
    extensions: [".js", ".json"],
  },
  plugins: [
    new HTMLwebpackPlugin({
      template: "./index.html",
      minify: {
        collapseWhitespace: isProd,
      },
    }),
    new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
    new CleanWebpackPlugin(),
    new CopyWebpackPlugin([

      {
        from: path.resolve(__dirname, "src/favicon.ico"),
        to: path.resolve(__dirname, "build"),
      },
    ]),
    new MiniCssExtractPlugin({
      filename: isDev ? `[name].css` : "css/[name].[hash:8].css",
    }),
    new ErrorOverlayPlugin(),
  ],

  devtool: isDev ? "cheap-module-source-map" : "",
  module: {
    rules: [
      {
        test: /\.css$/,
        use: cssLoader(),
      },

      {
        test: /\.(png|jpg|svg|gif)$/,
        loader: "file-loader",
        options: {
          outputPath: "img",
        },
      },
      {
        test: /\.(ttf|woff|woff2|eot)$/,
        use: ["file-loader"],
      },
      {
        test: /\.s[ac]ss$/,
        use: cssLoader("sass-loader"),
      },
      {
        test: /\.ts$/,
        exclude: /node_modules/,
        loader: "babel-loader",
        options: {
          presets: ["@babel/preset-env", "@babel/preset-typescript"],
          plugins: ["@babel/plugin-proposal-class-properties"],
        },
      },
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        use: [
          {
            loader: "babel-loader",
            options: {
              presets: ["@babel/preset-env", "@babel/preset-react"],
              plugins: ["@babel/plugin-proposal-class-properties"],
            },
          },
          "eslint-loader",
        ],
      },
    ],
  },
};

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
omgoshjoshcommented, Nov 20, 2020

so i actually just brought in all of react-dev-utils because its 2020 and the singularity is gonna happen soon anyway so why worry about performance or bundle size etc…

anyway, i have found what is working for me is based on a few things.

  1. https://github.com/facebook/create-react-app/issues/2344#issuecomment-303678582 a. first i tried what dan abramov (gaeron) says in this issue, using react-error-overlay
  2. https://github.com/facebook/create-react-app/issues/3097#issuecomment-380891629 a. then i got it up and running by installing the full react-dev-utils and using the suggestion of basically just replacing some strings instead of using the ones provided by abramov (gaeron) in the previous issue b. replace react-error-overlay with react-dev-utils/webpackHotDevClient c. replace react-error-overlay/middleware with react-dev-utils/errorOverlayMiddleware
  3. webpack config option: output.devtoolModuleFilenameTemplate a. here’s where this open issue comes in, basically i was finding that the link i would click in the browser would not send me to the editor as i had wished and per my investigation, i found that the url given were paths/filenames to files that obviously didn’t exist b. i found the link above which was admittedly not super clear to me, but looked familiar with a reference to this default value c. 'webpack://[namespace]/[resource-path]?[loaders]'
  4. https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/config/webpack.config.js#L231 a. and here’s what started opening the editor on click for me. basically i just copied the line for that webpack config key/value for dev mode and put it in my dev config and violá
'output': {
    // i added this one line to the rest of my output config in webpack.dev.config.js, which was otherwise left unchanged.
    'devtoolModuleFilenameTemplate': (info => path.resolve(info.absoluteResourcePath).replace(/\\/g, '/')),
}

so i guess what i’m trying to say is… that one config option is worth investigating as the potential solution somewhere for those who find this issue.

0reactions
gregbergecommented, Aug 30, 2021

@vjpr maybe we could find a way to make it work by default?

Read more comments on GitHub >

github_iconTop Results From Across the Web

CKEditor's click event not firing - Stack Overflow
For some reason, the click event never fires. However, if I listen to the doubleclick event, it fires when the editor is double...
Read more >
Ctrl + Click is not working VS Code Editor(Javascript file)
Steps to Reproduce: create a Javascript function; invoke that function; Do a Ctrl + click -> earlier it used to go to that...
Read more >
The Photo Editor button appears in the task bar, but the ...
... in the task bar, but the Microsoft Photo Editor window does not appear ... You click Restore Down (the middle button in...
Read more >
WordPress Visual Editor Not Working? Here's How to Fix It
Go to File Manager. · A list of folders will be displayed. Open the public_html folder and scroll down to the wp-config.php file....
Read more >
Code Navigation in Visual Studio Code
The command editor.action.goToTypeDefinition is not bound to a keyboard shortcut by default but you can add your own custom keybinding. Go to Implementation....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found