ulixee / platform

Home of the Ulixee Open Data Platform

Home Page:https://ulixee.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unexpected token (Note that you need @rollup/plugin-json to import JSON files)

dzxt opened this issue Β· comments

Hi! πŸ‘‹

Firstly, thanks for your work on this project! πŸ™‚

Today I used patch-package to patch @ulixee/datastore-packager@2.0.0-alpha.28 for the project I'm working on.

Reason

I encountered the following error while trying to deploy a datastore:

Error [RollupError]: Unexpected token (Note that you need @rollup/plugin-json to import JSON files)

The error occurred when attempting to read data from package.json like version, name, and id:

const pkg = require('../package.json');
const datastore = new Datastore({
  name: pkg.name,
  version: pkg.version,
  id: pkg.id,
  // other properties
});

module.exports = datastore;

To resolve this issue, I added @rollup/plugin-json to the Rollup plugins in rollupDatastore.js. This change ensures that JSON files can be imported correctly during the build process.

Thank you for considering this patch!

Here is the diff that solved my problem:

diff --git a/node_modules/@ulixee/datastore-packager/lib/rollupDatastore.js b/node_modules/@ulixee/datastore-packager/lib/rollupDatastore.js
index 2e8c2e7..132a36a 100644
--- a/node_modules/@ulixee/datastore-packager/lib/rollupDatastore.js
+++ b/node_modules/@ulixee/datastore-packager/lib/rollupDatastore.js
@@ -7,6 +7,7 @@ const Resolvable_1 = require("@ulixee/commons/lib/Resolvable");
 const TypedEventEmitter_1 = require("@ulixee/commons/lib/TypedEventEmitter");
 const sourcemaps_1 = require("./sourcemaps");
 const commonjs = require('@rollup/plugin-commonjs');
+const json = require('@rollup/plugin-json');
 const typescript = require('@rollup/plugin-typescript');
 async function rollupDatastore(scriptPath, options = {}) {
     const outDir = options.outDir ?? `${__dirname}/../`;
@@ -17,6 +18,7 @@ async function rollupDatastore(scriptPath, options = {}) {
             },
         }),
         commonjs({ transformMixedEsModules: true, extensions: ['.js', '.ts'] }), // the ".ts" extension is required }),
+        json()
     ];
     if (scriptPath.endsWith('.ts')) {
         plugins.unshift((0, plugin_replace_1.default)({

This issue body was partially generated by patch-package.