open-language / en-dictionary

En-Dictonary is a node.js module which makes works and their relations available as a package.
MIT License
10 stars 3 forks source link

Errors when requiring module #2

Closed christopheradorna closed 6 months ago

christopheradorna commented 4 years ago

Using example of:

const wordnet = require('en-wordnet')
const Dictionary = require('./index')

const start = async () => {
  const dictionary = new Dictionary(wordnet['3.0'])
  await dictionary.init()

  const result = dictionary.searchFor('yet')
}
start()

produces:

{ Error: Cannot find module './index'
    at Function.Module._resolveFilename (module.js:527:15)
    at Function.Module._load (module.js:476:23)
    at Module.require (module.js:568:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/<STRIPPED>/refactor_v1.js:21:20)
    at Module._compile (module.js:624:30)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3) code: 'MODULE_NOT_FOUND' }

So, I tried another way in:

const wordnet = require('en-wordnet');
const Dictionary = require(`${RootPath}/node_modules/en-dictionary/dist/index.js`).default; // Explicitly setting the path because exports is not a constructor
const start = async () => {
  const dictionary = new Dictionary(wordnet['3.0']);
  // const dictionary = new Dictionary('./index');
  await dictionary.init();
  const result = dictionary.searchFor('yet');
}
start();

Which produces:

Error: ENOENT: no such file or directory, open 'undefined/index.adj'

Thoughts?

sudhanshuraheja commented 4 years ago

@christopheradorna will look it up this weekend, looks like a bug.

lamansky commented 4 years ago

@christopheradorna: The following three lines found in the documentation example are wrong:

const wordnet = require('en-wordnet')
const Dictionary = require('./index')

const dictionary = new Dictionary(wordnet['3.0'])

Replace them with these lines instead:

const wordnet = require('en-wordnet').default
const Dictionary = require('en-dictionary').default

const dictionary = new Dictionary(wordnet.get('3.0'))

These changes will fix both of the error messages you were getting.

rektdeckard commented 4 years ago

The library is using ES6 module import/export syntax but it's not declared in package.json. @sudhanshuraheja might try adding "type": "module".

sudhanshuraheja commented 6 months ago

@christopheradorna the documentation has been fixed. (Thanks @lamansky) @rektdeckard this has now been updated.