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

TypeScript import other modules don't work #10

Open
mnaoumov opened this issue Jan 5, 2024 · 3 comments
Open

TypeScript import other modules don't work #10

mnaoumov opened this issue Jan 5, 2024 · 3 comments
Labels
bug Something isn't working enhancement New feature or request help wanted Extra attention is needed

Comments

@mnaoumov
Copy link
Contributor

mnaoumov commented Jan 5, 2024

Considering issue #7 fixed with my PR #8

!Scripts/test.ts

export function sayHello(name: string) {
  console.log(`hello ${name}`);
}

!Scripts/test2.ts

import { sayHello } from "./test";

export function sayHello2(name: string) {
  sayHello(name + name);
}

and invoke from the Developer Tools console

const test2 = await self.require.import("!Scripts/test2.ts");

getting error

plugin:modules:30507 Uncaught Error: ./test
    at L (plugin:modules:30506:3402)
    at Object.assign (plugin:modules:30506:4548)
    at eval (plugin:modules:30506:10230)
    at L (plugin:modules:30496:49899)
    at index.ts:1:1

It seems it couldn't find the relative path module

@mnaoumov
Copy link
Contributor Author

mnaoumov commented Jan 5, 2024

As per my further investigation, it seems in order to fix this issue properly, we need to find a way to bundle the module with all its dependencies and then compile them into a single JS module.

It's definitely possible but I am not that familiar with the TS bundlers and build. And moreover not so sure if @polyipseity would be interested in this to be done.

In my opinion, if we make this plugin work fine with TypeScript modules, it will open a huge opportunity for Obsidian plugin developers as we would be able to write mini-scripts in TS to test some functionality, which potentially going to be extracted into a plugin eventually.

Then we would need to migrate some missing functionality from the CustomJS plugin and the plugin would rule the world :) (at least mine for sure :) )

@polyipseity polyipseity added bug Something isn't working enhancement New feature or request labels Jan 11, 2024
@polyipseity
Copy link
Owner

It's definitely possible but I am not that familiar with the TS bundlers and build. And moreover not so sure if @polyipseity would be interested in this to be done.

In my opinion, if we make this plugin work fine with TypeScript modules, it will open a huge opportunity for Obsidian plugin developers as we would be able to write mini-scripts in TS to test some functionality, which potentially going to be extracted into a plugin eventually.

I am interested in it. There is no good way to intercept the import statement, unlike require. Bundling is one possible way, but I have thought of a lighter way to fix it: transforming the import statements into our require.import statements. This will require handling all possible import syntax though, so I have not really gotten around to do it yet.

@polyipseity polyipseity added the help wanted Extra attention is needed label Jun 6, 2024
@mnaoumov
Copy link
Contributor Author

mnaoumov commented Jul 3, 2024

As I couldn't use your plugin, I wrote an equivalent for your plugin that bypasses the mentioned issue.

https://github.com/mnaoumov/obsidian-fix-require-modules/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants