Skip to content

Build your personal knowledge base with Trilium Notes

build: Fix running webpack on ESM

Elian Doran3dbf8fb1c1eb
diff --git a/package.json b/package.json
index 6bf56cab86..4c5e0a0290 100644
--- a/package.json
+++ b/package.json
@@ -34,7 +34,7 @@
"build-backend-docs": "rimraf ./docs/backend_api && ./node_modules/.bin/jsdoc -c jsdoc-conf.json -d ./docs/backend_api src/becca/entities/*.js src/services/backend_script_api.js src/services/sql.js",
"build-frontend-docs": "rimraf ./docs/frontend_api && ./node_modules/.bin/jsdoc -c jsdoc-conf.json -d ./docs/frontend_api src/public/app/entities/*.js src/public/app/services/frontend_script_api.js src/public/app/widgets/basic_widget.js src/public/app/widgets/note_context_aware_widget.js src/public/app/widgets/right_panel_widget.js",
"build-docs": "npm run build-backend-docs && npm run build-frontend-docs",
- "webpack": "webpack -c webpack.config.ts",
+ "webpack": "cross-env NODE_OPTIONS=--loader=ts-node/esm webpack -c webpack.config.ts",
"test-jasmine": "cross-env TRILIUM_DATA_DIR=./data-test tsx ./node_modules/.bin/jasmine",
"test-es6": "tsx -r esm spec-es6/attribute_parser.spec.ts",
"test": "npm run test-jasmine && npm run test-es6",
diff --git a/src/services/asset_path.ts b/src/services/asset_path.ts
index 72a21fdb9f..ffb88f6268 100644
--- a/src/services/asset_path.ts
+++ b/src/services/asset_path.ts
@@ -1,3 +1,3 @@
-import packageJson from "../../package.json";
+import packageJson from "../../package.json" assert { type: "json" };
export default `assets/v${packageJson.version}`;
diff --git a/tsconfig.json b/tsconfig.json
index ee57f11303..5898cb05de 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"moduleResolution": "Bundler",
- "module": "ES2022",
+ "module": "ESNext",
"target": "ES2020",
"declaration": false,
"sourceMap": true,
diff --git a/webpack.config.ts b/webpack.config.ts
index 1c67bbe841..30293de06b 100644
--- a/webpack.config.ts
+++ b/webpack.config.ts
@@ -1,7 +1,9 @@
+import { fileURLToPath } from "url";
import path from "path";
import assetPath from "./src/services/asset_path.js";
-module.exports = {
+const rootDir = path.dirname(fileURLToPath(import.meta.url));
+export default {
mode: 'production',
entry: {
setup: './src/public/app/setup.js',
@@ -10,7 +12,7 @@ module.exports = {
},
output: {
publicPath: `${assetPath}/app-dist/`,
- path: path.resolve(__dirname, 'src/public/app-dist'),
+ path: path.resolve(rootDir, 'src/public/app-dist'),
filename: '[name].js',
},
devtool: 'source-map',