Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: Failed to resolve module specifier "mathjs". Relative references must start with either "/", "./", or "../". #3201

Closed
DasGestirn opened this issue May 10, 2024 · 6 comments
Labels

Comments

@DasGestirn
Copy link

DasGestirn commented May 10, 2024

Hi.

I downloaded mathjs using npm, but i'm having trouble actually using it. I need to use the complex numbers tools that the libray provides in one of my project's modules (a js file), but merely trying to import mathjs (as the documentation shows):

import { complex } from "mathjs";

Is enough to give this error:

Uncaught TypeError: Failed to resolve module specifier "mathjs". Relative references must start with either "/", "./", or "../".

Everything else in my project is working just fine.

Project folder structure:

VSCodium_v4EC5vACEj

How to reproduce the error and observe it:

  1. Install mathjs using npm;
  2. Try to import 'complex' from the mathjs library to the main.js module using the import { complex } from "mathjs command;
  3. Open the html file inside the browser using Live Preview and then go the console.
@DasGestirn
Copy link
Author

I have also tried doing this:

import { complex } from "../node_modules/complex.js/complex.js"

, which returns this error in the browser's console:

Uncaught SyntaxError: The requested module '../node_modules/complex.js/complex.js' does not provide an export named 'complex'

@josdejong
Copy link
Owner

How can we reproduce your issue?

@DasGestirn
Copy link
Author

DasGestirn commented May 10, 2024

How can we reproduce your issue?

Hi Jos.

I added the project's folder structure and how to reproduce the error in the main comment.

@DasGestirn
Copy link
Author

DasGestirn commented May 10, 2024

After cracking my head for hours, the solution i've found was to use a module bundler (Vite) and to use the import { create, all } from 'mathjs'; syntax to get it working. I didn't want to use Vite for such a small project, but that's how things have come to be.

Jos, before closing the issue, i'd like to know if there was a way to use the library without resorting to a module bundler, because it bloats my project massively. The documentation also doesn't mention the necessity of using one.

@josdejong
Copy link
Owner

So I understand that you want to use the library as ES module and without any bundlers like discussed in #1928?

You can use the browser bundle if you don't want to use a bundler, like mathjs/lib/browser/math.js.

@DasGestirn
Copy link
Author

So I understand that you want to use the library as ES module and without any bundlers like discussed in #1928?

You can use the browser bundle if you don't want to use a bundler, like mathjs/lib/browser/math.js.

Yes, correct. That was my intention.

Thanks, i will use this solution next time i need to use the library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants