michael-brade / LaTeX.js

JavaScript LaTeX to HTML5 translator
https://latex.js.org
MIT License
770 stars 58 forks source link

Critical dependency: the request of a dependency is an expression #127

Closed rm-arun-kumar closed 3 years ago

rm-arun-kumar commented 3 years ago

This is my code

import { parse, HtmlGenerator } from 'latex.js';

function getLatex (text) {
    const generator = new HtmlGenerator({ hyphenate: false});
    const result = parse(text, { generator }).htmlDocument();
    return result.body.innerHTML;
}

I am using rollup for my project. when I am running the rollup, end of the task I am getting the below error.

./node_modules/latex.js/dist/latex.js Critical dependency: the request of a dependency is an expression @ ./packages/src/js/index.js @ ./node_modules/react-styleguidist/lib/loaders/styleguide-loader.js!./node_modules/react-styleguidist/lib/client/index.js @ ./node_modules/react-styleguidist/lib/client/index.js @ multi ./node_modules/react-styleguidist/lib/client/index ./node_modules/react-dev-utils/webpackHotDevClient.js

What should I do?

michael-brade commented 3 years ago

First of all, I have no idea what this really means :-p But it seems that you are using webpack, not rollup -- or maybe rollup calls webpack somewhere. In any case, this is a webpack warning. So if it is just a warning, it should work anyway. Here is one of the issues that mentions this message: https://github.com/moment/moment/issues/5489

michael-brade commented 3 years ago

whoops, I just noticed that I quoted moment, not webpack. Well, in case this "warning" cannot be ignored, please give me a way to reproduce the problem so that I can take a look.

rm-arun-kumar commented 3 years ago

So if it is just a warning, it should work anyway

Yes.

But, I published this project as a NPM package and used it by installing it for another project. Since I used Webpack in that project, I am getting the below error

image2

All the contents from the latex.mjs file are thrown as an error.

I raised the above issue based on this error. If the critical dependency warning is not the reason for this issue then what can be the solution?.

rm-arun-kumar commented 3 years ago

The clear Screen shot is here.!

Screenshot from 2021-03-02 19-48-59

michael-brade commented 3 years ago

Yeah, it's a clear screenshot but I still have no idea what is going on. How can I reproduce this?

rm-arun-kumar commented 3 years ago

I am really sorry, I do not know how to explain this to you clearly. But resolved this.

Reason:- I missed the entry in the webpack.resolve.alias Solution:- After I added the 'latex.js': path.resolve(__dirname, "../node_modules/latex.js/dist/latex.js") line in webpack configuration, I am not getting any errors ( except Critical dependency warning ).

Thanks for your time @michael-brade :smile:

michael-brade commented 3 years ago

I see! That makes sense in a way :grin: But strange is: why doesn't it pick up the main entry in latex.js's package.json? Hm...

rm-arun-kumar commented 3 years ago

I also have that doubt. :thinking: .