Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic require failed #134

Open
Cupcc opened this issue Jan 14, 2025 · 0 comments
Open

Dynamic require failed #134

Cupcc opened this issue Jan 14, 2025 · 0 comments

Comments

@Cupcc
Copy link

Cupcc commented Jan 14, 2025

What version of pkg are you using?

6.2.0

What version of Node.js are you using?

22.13.0

What operating system are you using?

Windows 10

What CPU architecture are you using?

x86_64 intel 13600KF

What Node versions, OSs and CPU architectures are you building for?

node22-win-x64

Describe the Bug

Warning Cannot resolve 'path.join(dir_path, file)'
  E:\Projects\web\zjq-admin\models\index.js
  Dynamic require may fail at run time, because the requested file
  is unknown at compilation time and not included into executable.
  Use a string literal as an argument for 'require', or leave it
  as is and specify the resolved file name in 'scripts' option.

Expected Behavior

How to solve it ?

To Reproduce

package.json

 "scripts": [
  "./bin/www.js",
  "./models/examBatch.js",
  "./models/grade.js",
  "./models/user.js",
  "./models/worker.js",
  "./models/workerExamBatch.js"
  ],

Warning file in ./model/index.js

fs.readdirSync(__dirname)
  .filter((file) => {
    return (
      file.indexOf(".") !== 0 &&
      file !== basename &&
      file.slice(-3) === ".js" &&
      file.indexOf(".test.js") === -1
    );
  })
  .forEach((file) => {
    const model = require(path.join(__dirname, file))(
      sequelize,
      Sequelize.DataTypes,
    );
    models[model.name] = model;
  });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant