Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

jsep dependency error while using expression-eval #41

Closed
jeromecambon opened this issue Sep 18, 2020 · 6 comments
Closed

jsep dependency error while using expression-eval #41

jeromecambon opened this issue Sep 18, 2020 · 6 comments
Labels

Comments

@jeromecambon
Copy link

From TypeScript ('esnext' module), when trying to use expression-eval:

import {parse} from "expression-eval";
  
evalVariable(varName: string) {
    let ast = parse(varName);
    console.log("ast=" + ast);
}

I get the following error in the console:
Uncaught SyntaxError: The requested module '../../jsep/build/jsep.js' does not provide an export named 'default'

@donmccurdy
Copy link
Owner

Does import jsep from 'jsep'; work in your project? This may be specific to your build settings, or just an issue in the jsep module...

@jeromecambon
Copy link
Author

jeromecambon commented Sep 21, 2020

When I use:

import jsep from 'jsep';
evalVariable(varName: string) {
    let parseExp = jsep("1 + 1");
    console.log("parseExp=" + parseExp);
}

I get the same error:
Uncaught SyntaxError: The requested module '../../node_modules/jsep/build/jsep.js' does not provide an export named 'default'

Note that I've set typescript parameters 'esModuleInterop' and 'allowSyntheticDefaultImports' to true.

@dheerajkhatri
Copy link

@jeromecambon I am also facing the same issue, I modified import statement as:
import * as jsep from 'jsep'; and it worked fine.

It got modified here:
dd14637#diff-7aa4473ede4abd9ec099e87fec67fd57afafaf39e05d493ab4533acc38547eb8

@donmccurdy
Copy link
Owner

This change was made in #37, and fixed an error in @rbayliss's project with the previous syntax. Moreover, it matches what we actually do in the source file, index.js.

Since I'm not familiar with your various projects and build configurations, I'm not sure I know how to resolve this for everyone. I'm a bit tempted to remove the TypeScript definitions from this project, since it's difficult to maintain them when the source is not TypeScript, and TypeScript itself provides no robust tooling to check whether they're correct. 😕

@donmccurdy
Copy link
Owner

I believe this is fixed by 4.0.0. I've converted the library to typescript, so the type definitions are no longer written by hand. Note that tsconfig does use "esModuleInterop": true.

@tirithen
Copy link

tirithen commented May 6, 2021

I get the same error in a plain javascript project when in a test (using web-test-runner https://modern-web.dev/docs/test-runner/overview/) importing with:

import { parse, eval } from 'expression-eval';
SyntaxError: The requested module './../../jsep/build/jsep.js' does not provide an export named 'default'

Probably this package does not comply fully to ECMAScript modules import/export syntax, but maybe rather the older node/cjs types.

I'm trying an older version of the package to start with as mentioned on some of the other issues around the import errors.

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

No branches or pull requests

4 participants