Module not found: Error: Can't resolve in Webpack

41 Views Asked by At

I am using k6-typescript-template to load test a web application. So it basically uses babel-loader and webpack to convert typescript to javascript as k6 doesn't support typescript. I am receiving the below error when I try to run the npm run bundle.

ERROR in ./src/post-file-test.ts 24:0-66
Module not found: Error: Can't resolve '../../src/e2e/helpers/flows/loginFlow' in 'C:\Users\vignesh.t\SkillfitFrontend\k6-template-typescript\src'

ERROR in ./src/post-file-test.ts 25:0-76
Module not found: Error: Can't resolve '../../src/e2e/helpers/resetLocalStorage' in 'C:\Users\vignesh.t\SkillfitFrontend\k6-template-typescript\src'

ERROR in ./src/post-file-test.ts 26:0-77
Module not found: Error: Can't resolve '../../src/e2e/helpers/intercepts' in 'C:\Users\vignesh.t\SkillfitFrontend\k6-template-typescript\src'

3 errors have detailed information that is not shown.
Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.

my webpack.congif.js

const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const GlobEntries = require('webpack-glob-entries');
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin')

const config = {
  mode: 'production',
  entry: GlobEntries('./src/*test*.ts'), // Generates multiple entry for each test
  output: {
    path: path.join(__dirname, 'dist'),
    libraryTarget: 'commonjs',
    filename: '[name].js',
  },
  resolve: {
    extensions: ['.ts', '.js', '.tsx','.jsx'],
  },
  module: {
    rules: [
      {
        test: /\.(ts|tsx)$/,
        loader: 'babel-loader',
        exclude: /node_modules/,
        options:{
          presets: ["@babel/preset-typescript"]
        }
      },
    ],
  },
  target: 'web',
  externals: /^(k6|https?\:\/\/)(\/.*)?/,
  // Generate map files for compiled scripts
  devtool: "source-map",
  stats: {
    colors: true,
  },
  plugins: [
    new CleanWebpackPlugin(),
    new NodePolyfillPlugin(),
    // Copy assets to the destination folder
    // see `src/post-file-test.ts` for an test example using an asset
    new CopyPlugin({
      patterns: [{ 
        from: path.resolve(__dirname, 'assets'), 
        noErrorOnMissing: true 
      }],
    }),
  ],
  optimization: {
    // Don't minimize, as it's not used in the browser
    minimize: false,
  },
  resolve: {
    fallback:{
      "fs":false,
      path:false,
    },
  }
};
module.exports = config;

my package.json

{
  "name": "typescript",
  "version": "1.0.0",
  "repository": "ssh://[email protected]/k6io/example-typescript.git",
  "author": "Simon Aronsson <[email protected]>",
  "engines": {
    "node": "16 || 18"
  },
  "license": "MIT",
  "devDependencies": {
    "@babel/core": "7.23.7",
    "@babel/plugin-proposal-class-properties": "7.13.0",
    "@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
    "@babel/plugin-proposal-object-rest-spread": "7.13.8",
    "@babel/preset-env": "7.23.8",
    "@babel/preset-typescript": "7.23.3",
    "@types/k6": "^0.48.0",
    "@types/webpack": "5.28.5",
    "babel-loader": "9.1.3",
    "clean-webpack-plugin": "4.0.0",
    "copy-webpack-plugin": "^12.0.2",
    "typescript": "5.3.3",
    "webpack": "^5.90.3",
    "webpack-cli": "5.1.4",
    "webpack-glob-entries": "^1.0.1"
  },
  "scripts": {
    "bundle": "webpack"
  },
  "browser": {
    "[module-name]": false
  },
  "dependencies": {
    "@types/lucene": "^2.1.7",
    "lucene": "^2.1.1",
    "node-polyfill-webpack-plugin": "^3.0.0",
    "stream": "^0.0.2"
  }
}

What can be casuing the error? I have been working on just errors in the past week. This occurred today after I resolved the previous errors. Can anyone help me with this problem?

I have added .ts to the extensions in the resolve part in the webpack.config.js and changed the module.exports to export const config, gone through the directory path to ensure everything is correct. Changed every import statment by adding .ts to the files at the end. They made the situation worse.

Can anyone provide a solution to resolve this and get me out of this loophole?

0

There are 0 best solutions below