zthxxx / react-dev-inspector

jump to local IDE code directly from browser React component by just a simple click
https://react-dev-inspector.zthxxx.me
MIT License
1.13k stars 67 forks source link

How to debug and check what causes my goto code fail to work? #164

Closed alexya closed 2 months ago

alexya commented 3 months ago

I have followed the doc

  1. add the inspect component
    <>
      <Inspector
        onInspectElement={({ codeInfo }) => {
          gotoVSCode(codeInfo);
        }}
        onClickElement={params => {
          console.log(`The inspect element is clicked:`, params);
        }}
      />
      <App />
    </>
  2. add the middleware after the Express object is created
    
    const app = express();

app.use(launchEditorMiddleware);

3. And after running `node server.js` to start, and opening our website index.html from Chrome, press Ctrl+Shift+Alt+C, I can inspect the element in the UI. When clicking it, the console log will print the "The inspect element is clicked: " with the param data. The `codeInfo` is undefined I found. In the "Elements" of the Chrome developer tool's tab, I noticed that there is no `data-inspector-*` e.g. "data-inspector-relative-path" for any `div` element. 

I am not sure if there is something wrong with our webpack5 config. Is it caused by the @babel config as our project don't use the @babel, we are using the `esbuild-loader` and Typescript compiler (version 5.3.2). 
e.g. 

const packageDir = path.join(__dirname, ".."); const packagesDir = path.join(packageDir, "..");

// other code

  {
    // Ignore test and story files
    test: /^((?!([-.]test|\.story)\.).)*\.ts(x?)$/,
    // Ignore unnecessary folders
    exclude: [/node_modules/, /node-sample/, /__mocks__/],
    include: [packagesDir],
    loader: "esbuild-loader",
    options: {
      tsconfig: `${packageDir}/tsconfig.webpack.json`
    }
  }


Any help will be very helpful. Thanks.

p.s.:
"@babel/preset-env@^7.11.0"
"@babel/preset-react@^7.16.7"

webpack --version

  Packages:
    babel-loader: ^9.1.2 => 9.1.2
    clean-webpack-plugin: ^4.0.0 => 4.0.0
    copy-webpack-plugin: ^11.0.0 => 11.0.0
    esbuild-loader: ^4.0.2 => 4.0.2
    file-loader: ^4.0.0 => 4.3.0
    fork-ts-checker-webpack-plugin: ^8.0.0 => 8.0.0
    html-webpack-plugin: ^5.5.0 => 5.5.0
    license-checker-webpack-plugin: ^0.2.1 => 0.2.1
    node-loader: 2.0.0 => 2.0.0
    raw-loader: ^4.0.2 => 4.0.2
    serverless-webpack: ^5.11.0 => 5.11.0
    webpack: ^5.89.0 => 5.90.0
    webpack-bundle-analyzer: ^4.7.0 => 4.7.0
    webpack-cli: ^5.1.4 => 5.1.4
    webpack-dev-middleware: ^6.0.1 => 6.0.1
    webpack-dev-server: ^4.11.1 => 4.11.1
    webpack-manifest-plugin: ^5.0.0 => 5.0.0
    webpack-node-externals: ^3.0.0 => 3.0.0
    worker-loader: ^3.0.8 => 3.0.8
alexya commented 3 months ago

updated: I tried to add babel.config.js in my project root folder

module.exports = function(api) {
  const isDevelopment = api.env('development');

  return {
    "presets": [
      [
        "@babel/preset-react",
        {
          "runtime": "automatic",
          "development": isDevelopment
        }
      ]
    ]
  };
};

or using the .babelrc as

{
  "presets": [
    ["@babel/preset-react", {
      "runtime": "automatic",
      "development": true
    }]
  ]
}

and modified my webpack.config.js as

{
        // Ignore test and story files
        test: /^((?!([-.]test|\.story)\.).)*\.ts(x?)$/,
        // Ignore unnecessary folders
        exclude: [/node_modules/, /node-sample/, /__mocks__/],
        include: [packagesDir],
        use: [
          { loader: 'babel-loader' },
          {
            loader: "esbuild-loader",
            options: {
              tsconfig: `${packageDir}/tsconfig.webpack.json`
            }
          }
        ]
      }

still failed to generate the debugSource & data-inspector in the div.

zthxxx commented 3 months ago

@alexya Thanks for the detailed issue report! Here are some key points for troubleshooting:

Hope this helps!