Home computickets Module Not Found: Error: CAN't Resolve

Module Not Found: Error: CAN’t Resolve

Author

Date

Category

why this error occurs and how to fix it?

error in ./src/index.ts
Module Not Found: Error: CAN't Resolve './test' in 'Users / Maks / Documents / MyProgramms / TestProject / Src'
 @ ./src/index.ts 3: 13-30

Project File Structure:

 Project Structure

index.ts

import {user} from './test';
Let user = new user ('ivan');

test.ts

Export Class User {
  Name: String;
  Constructor (Name: String) {
    this.name = Name;
  }
}

package.json

{
 "Name": "TestProject",
 "Version": "1.0.0",
 "Description": "",
 "Main": "src / index.ts",
 "scripts": {
  "Build": "WebPack --Mode Development --Open"
 },
 "Author": "",
 "License": "ISC",
 "Dependencies": {},
 "DevDependencies": {
  "@ Types / Es6-shim": "^ 0.31.37",
  "@ Types / Express": "^ 4.16.0",
  "TS-Loader": "^ 4.4.2",
  "TypeScript": "^ 2.9.2",
  "WebPack": "^ 4.12.0",
  "WebPack-Cli": "^ 3.0.8",
  "WebPack-Dev-Server": "^ 3.1.4"
 }
}

WebPack.config.js

module.exports = {
  Entry: {
    Main: './src/index.ts'
  },
  Module: {
    Rules: [
      {
        Test: /\.js$/,
        EXCLUDE: / NODE_MODULES /,
          Use: {
          Loader: "Babel-Loader"
        }
      },
      {
        Test: /\.ts$/,
        EXCLUDE: / NODE_MODULES /,
        Loader: 'TS-Loader'
      },
    ]
  },
  Node: {
    FS: 'Empty',
    NET: 'Empty'
  },
  Target: 'Node'
};

I also tried to import via Require, use Awesome-TypeScript-Loader and update WebPack to the latest version.


Answer 1, Authority 100%

Add Property:

// webpack.config.js
RESOLVE: {
  Extensions: ['.js', '.ts']
}

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions