首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何调试运行时TypeError

如何调试运行时TypeError
EN

Stack Overflow用户
提问于 2021-07-13 00:54:14
回答 1查看 41关注 0票数 0

我用webpack构建了一个React+Typescript包。当我运行它并在浏览器中检查控制台时,我看到了这个神秘的堆栈跟踪。

错误发生在开机后1秒内,是控制台的第一条消息。

代码语言:javascript
复制
TypeError: n is not a function
    at bundle.js:2
    at Array.map (<anonymous>)
    at Gc.getBars (bundle.js:2)
    at Gc.drawOnCanvas (bundle.js:2)
    at X.drawOnCanvas (bundle.js:2)
    at X.componentDidUpdate (bundle.js:2)
    at X.componentDidMount (bundle.js:2)
    at hs (bundle.js:2)
    at Dl (bundle.js:2)
    at t.unstable_runWithPriority (bundle.js:2)

问题是,我不知道错误存在于代码中的哪里,因为堆栈跟踪信息非常少。

我如何才能找出问题出在哪一行代码?

这是我的tsconfig.json

代码语言:javascript
复制
{
  "compilerOptions": {
    "target": "es5",                                /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */
    "module": "commonjs",                           /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
    "strict" : true,
    "esModuleInterop": true,                        /* Enables emit 
    /* Advanced Options */
    "skipLibCheck": true,                           /* Skip type checking of declaration files. */
    "forceConsistentCasingInFileNames": true,        /* Disallow inconsistently-cased references to the same file. */
    "jsx" : "react",
  }
}

这是我的webpack.config.js

代码语言:javascript
复制
const path = require("path");
const HtmlWebPackPlugin = require("html-webpack-plugin");


const CopyPlugin = require("copy-webpack-plugin");


const htmlPlugin = new HtmlWebPackPlugin({
  template: "./src/index.html",
});

module.exports = {
  entry: "./src/index.tsx",
  

  module: {
    rules: [
      {
        test: /\.tsx?$/,
        use: "ts-loader",
        exclude: /node_modules/,
      },
      {
        test: /\.m?js/,
        resolve: {
          fullySpecified: false
        }
      }
    ],
  },


  resolve: {
    extensions: [".tsx", ".ts", ".js"],
    symlinks: true
  },

  output: {
    filename: "bundle.js",
    path: path.resolve(__dirname, "dist")
  },

  plugins: [
    htmlPlugin,
    new CopyPlugin({
      patterns: [
        { from: "public" }
      ],
    }),
  ],


  devServer: {
    contentBase: path.join(__dirname, 'dist'),
    compress: true,
    port: 9000 ,

    
  },

};
EN

Stack Overflow用户

回答已采纳

发布于 2021-07-13 00:58:55

如果您提供您的webpack.config.js文件将会很有帮助

一般来说,我会这样做

代码语言:javascript
复制
 node --inspect-brk=9229 ./node_modules/webpack/bin/webpack.js --config webpack.config.js --colors

调试webpack配置的问题。

官方文件显示,node-nightly。我个人还没有用过它。

只需将this添加到您的webpack.config

代码语言:javascript
复制
module.exports = {
  entry: "./src/index.tsx",
  

  module: {
    rules: [
      {
        test: /\.tsx?$/,
        use: "ts-loader",
        exclude: /node_modules/,
      },
      {
        test: /\.m?js/,
        resolve: {
          fullySpecified: false
        }
      }
    ],
  },
  devtool: 'source-map',
  .....
  .....
}
票数 1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68351205

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档