Import models from other location
See original GitHub issueHi,
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:
- Created 8 years ago
- Comments:5 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
please read https://github.com/keystonejs/keystone/blob/40563de928892deb9f707a4498439663d154443d/index.js#L162 so
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
Which loads from
./node_modules/keystone/
. Please share more of your code.@Gank … you’re very welcome! Let us know if you have any other questions.