obsidian-execute-code
obsidian-execute-code copied to clipboard
Unclear how to import packages for Typescript/Javascript
Hi! I absolutely love this tool. Thank you so much for developing it.
I can't really figure out how we are supposed to import packages in typescript. It says that we can use the {pre}
script to add our dependencies. I assume there we add all import x
, however the runtime will complain that it can't find that package. I can not figure out what is best practice for installing the package itself.
Thank you so much again for support and for developing this tool.
When you're importing, TS/JS expect you to have a node_modules
directory. The plugin creates a new file for each code block, so iirc that's why it can't find them.
You could try installing the dependencies globally with npm i -g <package>
; I think that will help?
Sorry :)
I tried adding it globally, but it didn't seem to work.
const _ = require('lodash')
Error: Cannot find module 'lodash'
Require stack:
- <repl>
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:101:18)
at eval (eval at <anonymous> (REPL6:1:7), <anonymous>:4:11)
at REPL6:1:7
at Script.runInContext (vm.js:144:12)
at REPLServer.defaultEval (repl.js:568:29)
at bound (domain.js:421:15)
at REPLServer.runBound [as eval] (domain.js:432:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '<repl>' ]
after successfully running npm i -g lodash
I can confirm also that it works when I try it in a regular node REPL in a terminal.
which node
/Users/me/.nvm/versions/node/v14.20.0/bin/node
which is the same as node path I've set in my Obsidian code execute config 🤔
/Users/me/.nvm/versions/node/v14.20.0/bin/node
Hey! I am running into the same issue. Maybe it has something to do with nvm? I am also using nvm and Obsidian Code Blocks don't find any packages that were installed.
Hi everyone,
I have the suspicion that this problem is connected to the fact that we currently do not allow access to the path variable. We are planning to add path, maybe this will fix it.
@MarcCoquand and @JustinS1209 can you try to update the plugin and then try it again? With release 1.7.1 the JS notebook mode can access the environment variables. This may fix it. Tell me how it worked, please.
@twibiral
I have similar issues but with Python. Should I open a new issue or you are working on paths within this one?
e.g. when my python code has importing it fails:
No module named 'gi'
Python imports work completely fine for me. Are you still having issues with them?
If the javascript/typescript import issue is resolved as well, then this issue could be closed.
Are you still having issues with them?
Just checked and still have issues