Steps to reproduce:
Results in the following output:
module.js:491
throw err;
^
Error: Cannot find module './'
at Function.Module._resolveFilename (module.js:489:15)
at Function.Module._load (module.js:439:25)
at Module.require (module.js:517:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/kevinbarbash/khan/KaTeX/cli.js:6:15)
at Module._compile (module.js:573:30)
at Object.Module._extensions..js (module.js:584:10)
at Module.load (module.js:507:32)
at tryModuleLoad (module.js:470:12)
at Function.Module._load (module.js:462:3)
Whatever the fix for this is, we'll want it to also work when running npm install katex.
Running cli.js from a node installation (there called katex) works fine atm.
If I change the line 6 to:
const katex = require("./katex");
I get
import ParseError from "./src/ParseError";
^^^^^^
SyntaxError: Unexpected token import
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/home/raoul/KaTeX/cli.js:6:15)
Now afaict this is something with new ES6 things.
@raoulb Are you using Node 8? I think import is only available there.
To fix this, we might want to build a version of cli.js via Babel.
No, not on 8 yet:
nodejs --version
v6.11.3
FWIW, here's how cli.js used to work:
git clone https://github.com/Khan/KaTeX
cd KaTeX
git submodule update --recursive --init
npm run dist (this takes a long time)
./cli.js
However, recently, this stopped working: now I get
.../KaTeX/dist/katex.js:10
})(window, function() {
^
ReferenceError: window is not defined
at Object.<anonymous> (/afs/csail.mit.edu/u/e/edemaine/Projects/KaTeX/dist/katex.js:10:4)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/afs/csail.mit.edu/u/e/edemaine/Projects/KaTeX/cli.js:6:15)
at Module._compile (module.js:569:30)
I assume this is because of our recent move to Webpack, or maybe Webpack 4. @ylemkimon any insight?
This is because built files are not committed on the master branch. To use the clone of KaTeX, it needs to be built:
git clone https://github.com/Khan/KaTeX
cd KaTeX
git submodule update --recursive --init
npm install
npm run build
./cli.js
There are ways to transpile(build) the project, on the fly(runtime) like babel-register, but this increases runtime overhead.
I think this issue would be wontfix.
@ylemkimon Agreed. The main thing left to do is document how to run cli.js. I've created #1483 for this.