Joplin: Html export for CLI: missing module “theme.js”

Created on 19 Apr 2020  ·  11Comments  ·  Source: laurent22/joplin

I am trying to export a notebook to html using the CLI,

$> joplin export . --format html --log-level debug

but it fails with the error message

Cannot find module '../../theme.js'

I have checked the log, but there is nothing interesting there. See below. I also checked if I could find theme.js somewhere, but the only path is /usr/lib/node_modules/npm/docs/src/theme.js which doesn't seem to be the file mentioned above.

--format raw and --format jex work as expected, though.

Any idea on how to continue debugging?

Environment

Joplin version: 1.0.163 (prod)
Platform/OS: Ubuntu 18.04 for WSL
nodejs v10.20.1 and npm version 6.14.4

Logfile

2020-04-19 18:46:53: "Profile directory: /home/fridde/.config/joplin"
2020-04-19 18:46:53: "Trying to load 0 master keys..."
2020-04-19 18:46:53: "Loaded master keys: 0"
2020-04-19 18:46:53: "ResourceFetcher: Auto-add resources: Mode: always"
2020-04-19 18:46:53: "ResourceFetcher: Auto-added resources: 0"

bug cli high

All 11 comments

I'm working on it.

I figured out that the error is occurred by this line const { themeStyle } = require('../../theme.js'); in CliClient > build > lib > services > InteropService_Exporter_Html.js which is trying to access theme.js file from build directory but it's missing and I searched for theme.js file and there's only file in ElectronClient directory so I tried copying that file in CliClient > build directory using

await utils.copyFile(`${__dirname}/../ElectronClient/theme.js`, `${buildDir}/theme.js`);

in gulpfile.js but then the error is different:

Cannot find module './gui/style/theme/light'                                                                                   
Require stack:                                                                                                                 
- /home/zkesarani/Dev/joplin/CliClient/build/theme.js                                                                          
- /home/zkesarani/Dev/joplin/CliClient/build/lib/services/InteropService_Exporter_Html.js                                      
- /home/zkesarani/Dev/joplin/CliClient/build/lib/services/InteropService.js                                                    
- /home/zkesarani/Dev/joplin/CliClient/build/command-export.js                                                                 
- /home/zkesarani/Dev/joplin/CliClient/build/app.js                                                                            
- /home/zkesarani/Dev/joplin/CliClient/build/main.js 

that is because of [Setting.THEME_LIGHT]: require('./gui/style/theme/light'), in theme.js and these files are missing so again I tried copying the directory using

await utils.copyDir(`${__dirname}/../ElectronClient/gui/style/theme`, `${buildDir}/gui/style/theme`);

now I ran the command: export . --format html --log-level debug in CliClient it returned error:
Could not create directory then I ran command: export ./note --format html --log-level debug and finally it worked! html file is exported in same directory with file note.html

@laurent22 Am i doing that right? Is that the correct fix for the issue? If so I can open up PR for the same. I'm clarifying here because I don't wanna open PRs which don't get merged.

Shared code should be moved to ReactNative/lib, so some refactoring is needed to move theme.js and its dependencies from ElectronClient to that lib folder. We should not use gulp for this.

Thank you sir. I'll will move theme.js to ReactNative/lib along with ElectronClient/gui/style/theme directory

But there's a problem moving theme.js from ElectronClient to ReactNativeClient/lib, it would affect 60+ files in ElectronClient/gui which required theme.js file So we need to change all those files to change the path of theme.js file. But now as you saying to move files to ReactNative/lib I think we should copy the files instead of moving so it won't affect ElectronClient and we will be able to use theme.js in ReactNativeClient and CliClient.

@laurent22 Should I move the files and refactor the ElectronClient files to replace the old path with new path ? or simply copy the files to ReactNative/lib ?

We only need to move theme.js and its dependencies from ElectronClient to that lib folder. Then update any file that requires theme.js. You can include it with "require('lib/theme')" (no need for ../../../....)

Thank you sir. I'll come up with PR soon.

You two work at an incredible speed! Great work!

Any idea when PR #3112 will be merged?

@kowalskidev
Sorry for bothering you again: To be able to use the html export until the PR merge and the eventual release, I thought I could make a quick-and-dirty fix and manually copy theme.js and light.js to where InteropService_Exporter_Html.js expects them, almost like you did in the gulp file.

But the error still appears and after a sanity check, i.e. modifying InteropService_Exporter_Html.js to log a string (which it doesn't), I see that running joplin export still uses the unmodified code.

I have cleared the npm cache, but as an amateur in node and npm, I feel like there is maybe some build step I am missing? Is there some precompiled version that is running instead of my modified source code?

@fridde merging PR may take some time but here is the quick-dirty fix:
Open the gulpfile.js in CliClient folder add this line just below line no. 15:

await utils.copyDir(`${__dirname}/../ElectronClient/gui/style/theme`, `${buildDir}/gui/style/theme`);

and add this line just below line no. 19

await utils.copyFile(`${__dirname}/../ElectronClient/theme.js`, `${buildDir}/theme.js`);

and now run npm start and try to export using command:
export ./note --format html it should generate HTML file in the CliClient folder with file name note.html

HTML export from the CLI app will not be supported for now. For this, please use the desktop app.

Was this page helpful?
0 / 5 - 0 ratings