最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Code: 'MODULE_NOT_FOUND', requireStack[] node.js - Stack Overflow

programmeradmin0浏览0评论

I'm busy with a project which creates a puppy database table in MySQL Workbench. It also makes use of WAMP server. I've created the puppy module as well as the puppy seeder. I have tried to run 'node seed.js' in the terminal in VS Code however I get the following error:

Error: Cannot find module 'C:\Users\PaigeF\OneDrive - (pany name here which I have removed intetionally)\Desktop\Sequelize-Pet-App\seed.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Here is my Puppy.model.js code:

const { DataTypes, Model } = require('sequelize');

class Puppy extends Model { }

Puppy.init({
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true,
        allowNull: false,
    },
    name: {
        type: DataTypes.STRING,
        allowNull: false,
        unique: true,
    },
    age: {
        type: DataTypes.INTEGER,
        allowNull: false,
    },
    favFood: {
        type: DataTypes.STRING,
        allowNull: true,
    },
},
    {
        sequelize,
        tableName: 'puppies',
        modelName: 'Puppy',
    });

model.exports = Puppy;

Here is my puppy.test.seeder.js code:

module.exports.seed = async () => {
    const Puppy = require('./puppy.model');
    Puppy.sequelize.sync();
}

And finally here is my seed.js code:

require('./Library/connection');
const Puppy = require('./modules/puppy.test.seeder');

seed();
async function seed() {
    console.log('Seeding Completed');
    process.exit();
}

I know this might not be the best/most efficient way, however, this is the layout that my pany wants me to use.

Thanks for all and any help/advise!

I'm busy with a project which creates a puppy database table in MySQL Workbench. It also makes use of WAMP server. I've created the puppy module as well as the puppy seeder. I have tried to run 'node seed.js' in the terminal in VS Code however I get the following error:

Error: Cannot find module 'C:\Users\PaigeF\OneDrive - (pany name here which I have removed intetionally)\Desktop\Sequelize-Pet-App\seed.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Here is my Puppy.model.js code:

const { DataTypes, Model } = require('sequelize');

class Puppy extends Model { }

Puppy.init({
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true,
        allowNull: false,
    },
    name: {
        type: DataTypes.STRING,
        allowNull: false,
        unique: true,
    },
    age: {
        type: DataTypes.INTEGER,
        allowNull: false,
    },
    favFood: {
        type: DataTypes.STRING,
        allowNull: true,
    },
},
    {
        sequelize,
        tableName: 'puppies',
        modelName: 'Puppy',
    });

model.exports = Puppy;

Here is my puppy.test.seeder.js code:

module.exports.seed = async () => {
    const Puppy = require('./puppy.model');
    Puppy.sequelize.sync();
}

And finally here is my seed.js code:

require('./Library/connection');
const Puppy = require('./modules/puppy.test.seeder');

seed();
async function seed() {
    console.log('Seeding Completed');
    process.exit();
}

I know this might not be the best/most efficient way, however, this is the layout that my pany wants me to use.

Thanks for all and any help/advise!

Share Improve this question asked Feb 4, 2021 at 7:52 PaigeFPaigeF 311 gold badge1 silver badge3 bronze badges 3
  • 1 I think that you need to export the module of the seed.js. Something like module.exports. – TheCoderGuy Commented Feb 4, 2021 at 7:58
  • 1 run in a separate console window (windows), or terminal (linux); u'll get rid of that error when u're at the dir of seed.js – Dan D Commented Feb 4, 2021 at 9:04
  • 1 @PaigeF got any solution for this – Okky Commented May 11, 2021 at 12:12
Add a ment  | 

2 Answers 2

Reset to default 0

I ran into the issue and solved it by firstly following these instructions... https://stackoverflow./a/60823141/9594269

but my cors.js file was in the \src folder so it could not find the file and threw this error.

Also, because I was using Visual Studio for my main project, when I got it to work it locked the terminal while it was running.

The solution was to run a windows mand prompt with administrator privileges, cd to the relevant folder with cors.js in, and the type "node cors" and it worked to run it in a seperate window, so I could then work with my main project in Visual Studio.

@Dee should take the credit for this in the ments section, but the above should clarify the process.

This gets it running but whether it then works to solve the CORS error from a Localhost is another issue - https://github./Rob--W/cors-anywhere/issues/217

Possible reasons: • seed.js does not exist in your project folder. • You’re in the wrong directory in the terminal. • File is named differently (e.g., Seed.js instead of seed.js), and file names are case-sensitive in some environments.

发布评论

评论列表(0)

  1. 暂无评论