Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module not found: Error: Can't resolve './lib/axios'

I'm trying to import axios in my project. However, for some reasons, webpack/axios is causing me big troubles when trying to build.

GroupService.ts

import axios, { AxiosResponse, AxiosInstance } from 'axios';

webpack --display-error-details errors

ERROR in ./~/axios/index.js
Module not found: Error: Can't resolve './lib/axios' in 'C:\dev\test-project\node_modules\axios'
resolve './lib/axios' in 'C:\dev\test-project\node_modules\axios'
  using description file: C:\dev\test-project\node_modules\axios\package.json (relative path: .)
  after using description file: C:\dev\test-project\node_modules\axios\package.json (relative path: .)
    using description file: C:\dev\test-project\node_modules\axios\package.json (relative path: ./lib/axios)
      as directory
        C:\dev\test-project\node_modules\axios\lib\axios doesn't exist
      no extension
        C:\dev\test-project\node_modules\axios\lib\axios doesn't exist
      .ts
        C:\dev\test-project\node_modules\axios\lib\axios.ts doesn't exist
[C:\dev\test-project\node_modules\axios\lib\axios]
[C:\dev\test-project\node_modules\axios\lib\axios]
[C:\dev\test-project\node_modules\axios\lib\axios.ts]
 @ ./~/axios/index.js 1:17-39
 @ ./src/services/GroupService.ts
 @ ./src/test-project.ts

Here's my webpack configurations.

webpack.config.js

/** Plugin settings **/
var jsOutputFile = 'dist/testproject.min.js';
var cssOutputFile = 'dist/styles.css';

/** Webpack configuration **/
var webpack = require("webpack");
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var extractCSS = new ExtractTextPlugin(cssOutputFile);

module.exports = {
  // application entry file
  entry: "./src/test-project.ts",

  // bundled application output file
  output: {
    path: __dirname,
    filename: jsOutputFile
  },

  // Currently we need to add '.ts' to the resolve.extensions array.
  resolve: {
    extensions: ['.ts']
  },

  // Source maps support ('inline-source-map' also works)
  devtool: 'source-map',

  // Add the loader for .ts files.
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        use: 'ts-loader'
      },
      {
        test: /\.scss$/,
        use: extractCSS.extract([
          {
            loader: 'css-loader'
          },
          {
            loader: 'sass-loader'
          }
        ])
      }
    ]
  },

  plugins: [
    new webpack.optimize.UglifyJsPlugin({
      minimize: true,
      sourceMap: true,
      compress: {
        warnings: true
      }
    }),
    extractCSS
  ]
};
like image 847
Gabriel Robert Avatar asked May 09 '17 18:05

Gabriel Robert


People also ask

What is Axios in react?

Axios is an HTTP client library based on promises. It makes sending asynchronous HTTP requests to REST endpoints easier and helps you perform CRUD operations. This REST endpoint/API could be an external API like the Google API, GitHub API, and so on – or it could be your own backend Node. js server.


1 Answers

For me the problem was that I didn't restart the yarn start service after installing axios the library was correctly installed in the app local node_modules directory.

Solution

Stopped the yarn service with CTRL+C and restarted it again with yarn start.

like image 160
chervl Avatar answered Oct 27 '22 09:10

chervl