You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Sails框架应用中模型无法导入的问题排查求助

Sails框架模型未定义问题排查求助

我正在协助他人排查一个基于Sails框架开发的JavaScript项目,此前无该框架使用经验。当前遇到模型无法正确导入的问题:

  • 调用用户注册API时触发ReferenceError: User is not defined,但User.js模型文件确实存在
  • bootstrap.js中实例化Settings对象时也出现类似未定义错误,只能注释掉这段逻辑才能让应用启动

目前使用Docker Compose运行极简容器,已确认容器内模型文件存在,排除了明显的容器化配置问题。

错误栈信息

ReferenceError: User is not defined
    at Object.fn (/app/api/controllers/auth/register.js:58:23)
    at wrapper (/node_modules/@sailshq/lodash/lib/index.js:3282:19)
    at parley.retry [as _handleExec] (/node_modules/machine/lib/private/help-build-machine.js:1016:29)
    at Deferred.exec (/node_modules/parley/lib/private/Deferred.js:286:10)
    at Deferred.switch (/node_modules/machine/lib/private/help-build-machine.js:1469:16)
    at Object._requestHandler [as auth/register] (/node_modules/machine-as-action/lib/machine-as-action.js:1153:27)
    at /node_modules/sails/lib/router/bind.js:248:46
    at routeTargetFnWrapper (/node_modules/sails/lib/router/bind.js:395:9)
    at Layer.handle [as handle_request] (/node_modules/express/lib/router/layer.js:95:5)
    at next (/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/node_modules/express/lib/router/layer.js:95:5)
    at /node_modules/express/lib/router/index.js:281:22
    at Function.process_params (/node_modules/express/lib/router/index.js:341:12)
    at next (/node_modules/express/lib/router/index.js:275:10)
    at next (/node_modules/express/lib/router/route.js:127:14)

相关配置文件

Dockerfile

FROM node:slim

COPY package.json ./

RUN npm install

docker-compose.yml

version: "3.7"
services:
  db:
    image: postgres
    restart: always
    environment:
      POSTGRES_PASSWORD: "localpassword"
    ports:
      - "5432:5432"
    volumes:
      - pgdata:/var/lib/postgresql/data
    networks:
      default:
        aliases:
          - database

  backend:
    build:
      dockerfile: Dockerfile
    working_dir: /app
    command: ["node", "app.js"]
    ports:
     - "1337:1337"
    networks:
      default:
        aliases:
          - backend
    volumes:
      - ./:/app

networks:
  default:

volumes:
  pgdata:
    driver: local

内容的提问来源于stack exchange,提问作者josephkibe

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 17:05:59