question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Import models from other location

See original GitHub issue

Hi,

I was trying to import a common model directory. The following code works:

// Require keystone
var keystone = require('keystone');
keystone.init({});
keystone.import('models');
console.log(keystone.paths);

But if I change the models location it stops working, for example:

keystone.import('../models');

Error output:

module.js:340
    throw err;
    ^
Error: Cannot find module 'keystone'
  at Function.Module._resolveFilename (module.js:338:15)
  at Function.Module._load (module.js:280:25)
  at Module.require (module.js:364:17)
  at require (module.js:380:17)
  at Object.<anonymous> (/test/models/User.js:1:78)
  at Module._compile (module.js:456:26)
  at Object.Module._extensions..js (module.js:474:10)
  at Module.load (/test/app/node_modules/keystone/node_modules/cloudinary/node_modules/coffee-script/lib/coffee-script/register.js:45:36)
  at Function.Module._load (module.js:312:12)
  at Module.require (module.js:364:17)
  at require (module.js:380:17)
  at /test/node_modules/keystone/index.js:209:23
  at Array.forEach (native)
  at doImport (/test/app/node_modules/keystone/index.js:196:28)
  at [object Object].Keystone.import (/test/app/node_modules/keystone/index.js:218:9)
  at Object.<anonymous> (/test/test.js:6:16)
  at Module._compile (module.js:456:26)
  at Object.Module._extensions..js (module.js:474:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:312:12)
  at Function.Module.runMain (module.js:497:10)
  at startup (node.js:119:16)
  at node.js:935:3

Any tips on how I can achieve this?

Thanks!

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
morenoh149commented, Mar 29, 2015

please read https://github.com/keystonejs/keystone/blob/40563de928892deb9f707a4498439663d154443d/index.js#L162 so

keystone.import('../models');

would load models outside of the current project (doubt that’s what you want).

And for the second question, you’re trying to require keystone from a nonstandard location. Usually you’d do

var keystone = require('keystone')

Which loads from ./node_modules/keystone/. Please share more of your code.

0reactions
estillescommented, Apr 9, 2015

@Gank … you’re very welcome! Let us know if you have any other questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Import models to Vertex AI
This guide describes how to import models into the Vertex AI Model Registry. After you import your model, it is visible in the...
Read more >
Importing files from different folder - python
When importing a file, Python only searches the directory that the entry-point script is running from and sys.path which includes locations such as...
Read more >
Import Models
Click Models to navigate to the Models category view. · Click Import. The Import Models window appears. · Click Choose a location ·...
Read more >
Import models-cells from other files - [Archived] AskInga Wiki
MicroStation V8 - You can easily import models from other files into your active design by selecting the Import Models button in the...
Read more >
Django models outside of models.py
<file> import <model_class> -- must be used in __init__.py for every model declared in .py files inside the models folder. With this layout...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found