1

I try to import mathjs as a module in a browser (client side). I copied this file on the server, and then try to import the JS module, but it always fails. Here are some trial I already made:

import { mathjs } from "./math.min.js"

SyntaxError: The requested module './../modules/math.min.js' does not provide an export named 'mathjs'

import { math } from "./math.min.js"

SyntaxError: The requested module './../modules/math.min.js' does not provide an export named 'math'

import { create, all } from "./math.min.js"

SyntaxError: The requested module './math.min.js' does not provide an export named 'all'

I also try:

import("/math.min.js");

Uncaught (in promise) TypeError: Cannot set property 'math' of undefined

Note that the path is OK, I checked. I'm probably missing something, but I can't find what I am doing wrong. Any help is welcome.

Here is a repl.it with the code: https://repl.it/@FifiLulu/NewJollyRoutes

Fifi
  • 3,360
  • 2
  • 27
  • 53

1 Answers1

0

You'll need to add:

<script type="module">

to your html file.

RowanC
  • 1,611
  • 10
  • 16
  • That's not the issue. The file index.js is imported with `import("/index.js")`. It works with other modules. – Fifi Apr 30 '20 at 07:12