TypeError: createAgent is not a function

When using the basic example:

require('dotenv').config();

// Import the requirements
const { createAgent } = require('@forestadmin/agent');

// Create your Forest Admin agent
createAgent({
  // These process.env variables should be provided in the onboarding
  authSecret: process.env.FOREST_AUTH_SECRET,
  agentUrl: process.env.FOREST_AGENT_URL,
  envSecret: process.env.FOREST_ENV_SECRET,
  isProduction: process.env.NODE_ENV === 'production',
})
  .mountOnStandaloneServer(3000)
  .start();

I just upgraded to a new version today and it gives me this error. I’ve installed Forest yesterday and had another issue… Spent already a day on this, just using this example from the admin panel… Pretty frustrated with this, as I’m using Forest in multiple projects for years, maybe 4 or so and each time I set it up it’s a continuous quest…

Hello @Dmitrii_Ponomarev,

Thanks for joining the community. I’m glad that you’re keeping with Forest Admin, and we are currently working to make the experience smoother. This new agent should normally help to do so, but if anything is missing or incorrect in the creation process, we will fix it.

To start with the beginning, can you please share with us the basic info that are requested when creating a new post in the “help me” section please?

Context

  • Project name: …
  • Team name: …
  • Environment name: …
  • Agent type & version: …
  • Recent changes made on your end if any: …

I need the exact version and package name present in your package.json to be sure that you’re using the right one.

In the meantime, you might need to check the documentation specific to this agent here.

Hi, it’s a brand new Project:

Team: dmitrii@digitaldali.ru / Personal
Project name: ny22
Agent: standalone
package.json:

    "@forestadmin/agent": "^1.0.0-beta.1",
    "@forestadmin/datasource-mongoose": "^1.0.0-beta.13",

Ok, thanks for the info.

It seems that you don’t use the latest version. Do you remember which instructions you followed, and if you modified something in the commands? Just to check if we need to change something in the docs or in the project creation process.

Your issue can be fixed by running

npm install @forestadmin/agent@beta @forestadmin/datasource-mongoose@beta

Both packages are about to be released, and can be considered as safe to use, but right now the stable version is not released yet.

Hi @GuillaumeGautreau, thank you for your reply.
I think I’ve just done npm i @forestadmin/agent

So the server started with @beta version and I was able to add a few models. But now I’m getting this error:

(node:4868) UnhandledPromiseRejectionWarning: OPError: Agent is not started
    at processResponse (/root/new-you-prod/node_modules/openid-client/lib/helpers/process_response.js:38:13)
    at Function.register (/root/new-you-prod/node_modules/openid-client/lib/client.js:1453:26)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async Authentication.bootstrap (/root/new-you-prod/node_modules/@forestadmin/agent/dist/agent/routes/security/authentication.js:36:15)
    at async Promise.all (index 3)
    at async ForestAdminHttpDriver.getRouter (/root/new-you-prod/node_modules/@forestadmin/agent/dist/agent/forestadmin-http-driver.js:22:9)
    at async AgentBuilder.start (/root/new-you-prod/node_modules/@forestadmin/agent/dist/builder/agent.js:205:24)
(node:4868) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)

Models are very basic, here is the last one I added:

const mongoose = require('mongoose');
const { ObjectId } = mongoose.Schema.Types;

const AdviceSchema = mongoose.Schema({
    title: String,
    text: String,
    img: String,
    author: String,
    date:{type:Date},

    season:{ref:"Season", type:ObjectId}
});

const Advice = mongoose.model('Advice', AdviceSchema);
module.exports=Advice;

process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0
const mongoose = require('mongoose');
require('dotenv').config();

// Import the requirements
const { createAgent } = require('@forestadmin/agent');
const { createMongooseDataSource } = require('@forestadmin/datasource-mongoose');

const Season = require("./models/Season");
const User = require("./models/User");
const Advice = require("./models/Advice");

mongoose.connect('mongodb://localhost/' + process.env.DB_NAME);




  mongoose.connection.once('open', () => {
// Create your Forest Admin agent
createAgent({
  // These process.env variables should be provided in the onboarding
  authSecret: process.env.FOREST_AUTH_SECRET,
  agentUrl: process.env.FOREST_AGENT_URL,
  envSecret: process.env.FOREST_ENV_SECRET,
  isProduction: process.env.NODE_ENV === 'production',
})
.addDataSource(createMongooseDataSource(mongoose.connection))
  .mountOnStandaloneServer(6002)
  .start();
});

Hey @Dmitrii_Ponomarev :wave:

I can’t spot anything special in what you shared, the code looks good to me.

Do you have any other (non-error) logs displayed?