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

@rollup/plugin-json error using @argdown-node #222

Closed
amdecker opened this issue Apr 12, 2021 · 7 comments
Closed

@rollup/plugin-json error using @argdown-node #222

amdecker opened this issue Apr 12, 2021 · 7 comments

Comments

@amdecker
Copy link

Hi,

I'm trying to write a plugin for Obsidian using @argdown-node. I added import {argdown} from "@argdown/node"; and console.log(argdown); to the sample Obsidian plugin after running node install @argdown/node --save-dev and I got this error. Has anyone used @argdown-node before and have any tips for getting it up and running?

Here is the error I received:
[!] Error: Unexpected token (Note that you need @rollup/plugin-json to import JSON files) node_modules\axios\package.json (2:9) 1: { 2: "_from": "axios@^0.21.1", ^ 3: "_id": "axios@0.21.1", 4: "_inBundle": false, Error: Unexpected token (Note that you need @rollup/plugin-json to import JSON files) at error (C:\Users\adder\Documents\obsidian-notes\.obsidian\plugins\obsidian-argdown-plugin\node_modules\rollup\dist\shared\rollup.js:5305:30) at Module.error (C:\Users\adder\Documents\obsidian-notes\.obsidian\plugins\obsidian-argdown-plugin\node_modules\rollup\dist\shared\rollup.js:9750:16) at Module.tryParse (C:\Users\adder\Documents\obsidian-notes\.obsidian\plugins\obsidian-argdown-plugin\node_modules\rollup\dist\shared\rollup.js:10156:25) at Module.setSource (C:\Users\adder\Documents\obsidian-notes\.obsidian\plugins\obsidian-argdown-plugin\node_modules\rollup\dist\shared\rollup.js:10057:24) at ModuleLoader.addModuleSource (C:\Users\adder\Documents\obsidian-notes\.obsidian\plugins\obsidian-argdown-plugin\node_modules\rollup\dist\shared\rollup.js:18396:20) at async ModuleLoader.fetchModule (C:\Users\adder\Documents\obsidian-notes\.obsidian\plugins\obsidian-argdown-plugin\node_modules\rollup\dist\shared\rollup.js:18452:9) at async Promise.all (index 9) at async ModuleLoader.fetchStaticDependencies (C:\Users\adder\Documents\obsidian-notes\.obsidian\plugins\obsidian-argdown-plugin\node_modules\rollup\dist\shared\rollup.js:18478:34) at async Promise.all (index 0) at async ModuleLoader.fetchModule (C:\Users\adder\Documents\obsidian-notes\.obsidian\plugins\obsidian-argdown-plugin\node_modules\rollup\dist\shared\rollup.js:18454:9)

@christianvoigt
Copy link
Owner

Hi, this seems to be an issue of bundling axios with rollup. I would first search for similar issues in the rollup and axios repositories (a quick search brought up some results).

It seems as if Rollup is trying to import the package.json of Axios instead of the package's entry point, which is strange.

As a workaround you could import the Argdown app from the @argdown/core package (which does not use Axios):

import {argdown} from "@argdown/core";

It is not as powerful as the node version, but many features will still work (it is used in the Sandbox and the Argdown preview of the VSCode extension).

@amdecker
Copy link
Author

amdecker commented Apr 13, 2021

Great thanks! I seemed to solve that issue, but now I get a runtime error both when I use argdown-node and argdown-core.

When using argdown-node this error appears:

Plugin failure: obsidian-sample-plugin Error: Cannot find module 'fsevents'
Require stack:
- electron/js2c/renderer_init
    at Module._resolveFilename (internal/modules/cjs/loader.js:972)
    at Function.i._resolveFilename (electron/js2c/renderer_init.js:35)
    at Module._load (internal/modules/cjs/loader.js:848)
    at Function.f._load (electron/js2c/asar_bundle.js:5)
    at Module.require (internal/modules/cjs/loader.js:1032)
    at require (internal/modules/cjs/helpers.js:72)
    at de (app.js:1)
    at s (app.js:1)
    at anonymous (eval at <anonymous> (app.js:1), <anonymous>:15:20)
    at e.<anonymous> (app.js:1)

And when using argdown-core I get this:

Plugin failure: obsidian-sample-plugin Error: Cannot find module 'mdurl'
Require stack:
- electron/js2c/renderer_init
    at Module._resolveFilename (internal/modules/cjs/loader.js:972)
    at Function.i._resolveFilename (electron/js2c/renderer_init.js:35)
    at Module._load (internal/modules/cjs/loader.js:848)
    at Function.f._load (electron/js2c/asar_bundle.js:5)
    at Module.require (internal/modules/cjs/loader.js:1032)
    at require (internal/modules/cjs/helpers.js:72)
    at de (app.js:1)
    at s (app.js:1)
    at anonymous (eval at <anonymous> (app.js:1), <anonymous>:15368:1)
    at e.<anonymous> (app.js:1)

I am using windows, so I don't know why fsevents should even be involved. Is it related to this?: #104

I looked in package-lock.json and both fsevents and mdurl are in there. fsevents is marked optional too...

Do you have any thoughts? Thanks for the help!

(edit: fixed codeblock, typo)

@christianvoigt
Copy link
Owner

Hi @amdecker,
should I leave this open or is this no longer a problem in your new version?

@amdecker
Copy link
Author

thanks for your help, I'll try again later today or tomorrow and see how things go and let you know -- so for now could you leave it open?

@amdecker
Copy link
Author

I'm still running into the same fsevents error as before. It looks like electron (obsidian is an electron app) does not play well with fsevents paulmillr/chokidar#618 and fsevents/fsevents#131. However the fix described in those issues requires bundling fsevents with the electron app, which I can't do because obsidian is not open source.

Is it possible to use argdown without any reference to fsevents? Is it possible that fsevents is not correctly labelled as optional somewhere?

One hacky solution would be to have users install the argdown cli and then run exec from within my plugin, but if I can use the argdown/node or core package, that would be ideal. I am thoroughly stuck, so if you have any ideas, let me know -- though if this doesn't interest you or you simply don't have the time, that's perfectly ok.

@christianvoigt
Copy link
Owner

I do not use fsevents directly, only through Chokidar. Chokidar is used in the AsyncArgdownApplication of @argdown/node to enable the user to "watch" files for changes. As I am working on a Windows computer, fsevents is not installed when I install @argdown/node, so it is only optional. Maybe there is a way to tell Chokidar to not install fsevents? I have not looked into this.

@argdown/core does not use Chokidar or fsevents. It uses Mocha as a devDependency for testing. Mocha uses Chokidar. But if you install @argdown/core devDependencies should not be installed. You can check why Chokidar is installed in your project by running yarn why chokidar or npm explain chokidar.

@amdecker
Copy link
Author

I haven't been able to figure it out, so I went with depending on users installing argdown-cli for now.

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

No branches or pull requests

2 participants