代码之家  ›  专栏  ›  技术社区  ›  David Geismar

类构造函数控制器无法在没有“new”错误的情况下调用Stimulus+webpack

  •  0
  • David Geismar  · 技术社区  · 3 年前

    我有一个项目,我试图安装刺激和 stimulus tailwind components

    我添加了webpack和一个webpack配置文件:

    // Webpack uses this to work with directories
    const path = require('path');
    
    // This is the main configuration object.
    // Here, you write different options and tell Webpack what to do
    module.exports = {
      module: {
        rules: [
          {
            test: /\.js$/,
            exclude: /(node_modules)/,
            use: {
              loader: 'babel-loader',
              options: {
                presets: ['@babel/preset-env']
              }
            }
          }
        ],
      },
      // Path to your entry point. From this file Webpack will begin its work
      entry: './src/js/index.js',
    
      // Path and filename of your result bundle.
      // Webpack will bundle all JavaScript into this file
      output: {
        path: path.resolve(__dirname, 'dist'),
        publicPath: '',
        filename: 'bundle.js'
      },
    
      // Default mode for Webpack is production.
      // Depending on mode Webpack will apply different things
      // on the final bundle. For now, we don't need production's JavaScript
      // minifying and other things, so let's set mode to development
      mode: 'development'
    };
    

    据我所知,使用babel应该将我的es6js转换为与浏览器兼容的js。

    然后在src/index.js中,我得到了刺激代码:

    //启动刺激JS

    import { Application } from "@hotwired/stimulus"
    
    const application = Application.start();
    
    // Import and register all TailwindCSS Components
    import { Alert, Autosave, Dropdown, Modal, Tabs, Popover, Toggle, Slideover } from "tailwindcss-stimulus-components"
    application.register('alert', Alert)
    application.register('autosave', Autosave)
    application.register('dropdown', Dropdown)
    application.register('modal', Modal)
    application.register('tabs', Tabs)
    application.register('popover', Popover)
    application.register('toggle', Toggle)
    application.register('slideover', Slideover)
    

    在html文件中,我需要我的bundle.js:

    <script src="../dist/bundle.js"></script>
    

    然而,我一直收到这样的错误:

    未捕获(在promise中)TypeError:类构造函数控制器不能 在没有“new”的情况下调用 从…起 tailwindcss刺激组件.module.js:12

    这里有一个链接 project

    我的webpack设置有问题吗?如何修复此错误?

    0 回复  |  直到 3 年前