如何在reactjs / typescript webpack项目中导入.jsfiles?

时间:2017-10-04 05:02:25

标签: javascript reactjs typescript webpack

我正在尝试在名为main.tsx的React& Typescript组件中导入一个名为Auth.js的模块。我的webpack.config的一部分是:

module.exports = {
  entry: entries,
  output: output,
  devtool: devtool,
  resolve: { extensions: ['.ts','.js','.tsx','.css'] },
  module: {
    rules: [
      { 
        test:/\.tsx?$/, 
        exclude:/node_modules/,
        use:[{ loader:'ts-loader'}] 
      },
      { 
        test:/\.css$/, 
        exclude:/node_modules/,
        include:[path.resolve(__dirname,"src")],
        use:[ 
          { loader:'style-loader'},
          { loader:'typings-for-css-modules-loader', options:{ modules:true,namedExport:true,camelCase:true } }
        ]          
      }
    ]
  },
  plugins: plugins
};

当我运行webpack时,我收到此错误:

ERROR in ./src/containers/main.tsx
(14,23): error TS6143: Module '../Auth/Auth' was resolved to '/Users/me/src/Auth/Auth.js', but '--allowJs' is not set.

ERROR in ./src/Auth/Auth.js
Module parse failed: /Users/me/src/Auth/Auth.js Unexpected token (6:8)
You may need an appropriate loader to handle this file type.

我需要在配置中指定什么来处理我的应用程序中的Auth.js文件?

更新:我应用了建议并解决了allowJs问题。但是第二条错误消息,这是我怀疑的webpack错误没有解决。那么如何更新webpack配置以便加载.js文件呢?

0 个答案:

没有答案