0

I am trying to import a module called Auth.js in my React&Typescript component called main.tsx. Part of my webpack.config is :

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
};

When I run webpack I get this error:

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.

What do I need to specify in the config to handle the Auth.js file in my application?

UPDATE: I applied the suggestion and the resolved the allowJs issue. However the second error message, which would be a webpack error I suspect is not resolved. So how can I update the webpack configuration so it will allow for .js files to be loaded?

bier hier
  • 20,970
  • 42
  • 97
  • 166
  • Possible duplicate of [Requiring a JavaScript Node.js module in TypeScript (allowJs' is not set)](https://stackoverflow.com/questions/42867688/requiring-a-javascript-node-js-module-in-typescript-allowjs-is-not-set) – Panther Oct 04 '17 at 05:05
  • If updating tsconfig does not help, try updating the ts-loader name in webpack config to `ts-loader?allowJsEntry=true`, might help. https://github.com/TypeStrong/ts-loader/issues/163 – shriidhar Oct 04 '17 at 06:04

0 Answers0