Skip to content

[BUG] Error when importing 'gun/lib/time.js' in nodejs #1360

Open
@matubu

Description

@matubu

When I attempt to import 'gun/lib/time.js' within Node.js, I encounter the following error. Here is a minimal reproducible example:

{
  "dependencies": {
    "gun": "^0.2020.1239"
  },
  "type": "module"
}
import Gun from 'gun/gun.js';
import 'gun/lib/time.js';
$ npm i
$ node example.js
Hello wonderful person! :) Thanks for using GUN, please ask for help on http://chat.gun.eco if anything takes you longer than 5min to figure out!
REDACTED/node_modules/gun/lib/time.js:3
        var ify = Gun.node.ify, u;
                           ^

TypeError: Cannot read properties of undefined (reading 'ify')
    at REDACTED/node_modules/gun/lib/time.js:3:21
    at Object.<anonymous> (REDACTED/node_modules/gun/lib/time.js:138:2)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at cjsLoader (node:internal/modules/esm/translators:345:17)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:294:7)
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)

Node.js v20.10.0

This error occurs both when importing using the require and import syntax. Additionally, the error persists when attempting to import 'gun' instead of 'gun/gun.js'. However, it does not occur when running the code in the browser using a script tag to import gun as shown below:

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
</head>
<body>
	<script src="./node_modules/gun/gun.js"></script>
	<script src="./node_modules/gun/lib/time.js"></script>

	<script>
		console.log(Gun().time);
	</script>
</body>
</html>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions