Friday 5 May 2017

Webpack alias doesn't work and says the file doesn't exist

I checked some question in StackOverflow but this problem it's not as same as my problem.

I have problem with requiring a file in my project: require(testLog)

If I put the directory in module:[] everything works well but if I use the file name with alias it doesn't work. Everything seems to be right even in webpack --display-error-details I checked the path of the file which I required in my project and it was the exact path of that file. However, even the path is right but I got this error :

as directory

/Users/pip/projects/react-blog/app/testLog.jsx doesn't exist

no extension

Field 'browser' doesn't contain a valid alias configuration /Users/pip/projects/react-blog/app/testLog.jsx doesn't exist

Here is webpack code for alias:

resolve: {

    modules: [
      __dirname,
      'node_modules',
      './app/components',
      './app/api',

    ],
    alias: {
      'testLog' : path.resolve(__dirname, './app/testLog.jsx')
    },
    extensions: [' ','.scss', '.js', '.jsx']
  }



via Amir hossein gholzam

No comments:

Post a Comment