0

I'm trying to use webpack to compile (typescript files) and bundle up my source code. Here is my current webpack.config.js file:

const path = require('path')

module.exports = {
  devtool: 'eval-source-map',
  entry: './src/main.ts',
  module: {
    rules: [
      {
        test: /\.ts$/,
        use: 'ts-loader',
        include: [
          path.resolve(__dirname, 'src'),
        ]
      }
    ]
  },
  resolve: {
    extensions: ['.ts', '.js']
  },
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist')
  }
}

I also have big.js installed as a node module. However, when I run webpack and bundle all the files into bundle.js. It runs the bundled code (known by console.log messages printing to console), but I get the following error in the browser:

Uncaught Error: Cannot find module 'big.js'

and it points to the following line of code:

import Big from "big.js";

I know big.js is included because looking in the bundle.js file, the top of the file has the big.js bundled (shown as below):

(()=>{var __webpack_modules__={302:function(module,exports,__webpack_require__){eval("var __WEBPACK_AMD_DEFINE_RESULT__;/*\r\n *  big.js v6.1.1\r\n *  A small, fast, easy-to-use library for arbitrary-precision decimal arithmetic.\r\n *  Copyright (c) 2021 Michael Mclaughlin\r\n *  https://github.com/MikeMcl/big.js/LICENCE.md\r\n */\r\n;(function (GLOBAL) {\r\n  'use strict';\r\n  var Big,\r\n\r\n\r\n/...

This is my first time using webpack and big.js so the solution is hopefully simple, but if someone knew what the issue was, your help would be appreciated. If any further information is needed, let me know.

1 Answers1

-1

Might be a bit late, but have you tried requiring it instead of importing it?

const Big = require('big.js');
viktorka
  • 11
  • 2
  • this would be better said in a comment instead of an answer. – Mustafa Oct 11 '22 at 11:21
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 11 '22 at 11:53