Skip to content

Error when running example code for mxpx-openai-node - SyntaxError: Cannot use import statement outside a module #3

@notnotrishi

Description

@notnotrishi
/Users/rishi/Projects/mcpx-openai-chat/index.js:2 import { McpxOpenAI } from "@dylibso/mcpx-openai"; ^^^^^^

SyntaxError: Cannot use import statement outside a module at internalCompileFunction (node:internal/vm:77:18) at wrapSafe (node:internal/modules/cjs/loader:1288:20) at Module._compile (node:internal/modules/cjs/loader:1340:27) at Module._extensions..js (node:internal/modules/cjs/loader:1435:10) at Module.load (node:internal/modules/cjs/loader:1207:32) at Module._load (node:internal/modules/cjs/loader:1023:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12) at node:internal/main/run_main_module:28:49

For now, in order to fix it and run, I added type as module in package.json and renamed index.js to index.mjs (i guess either should work?)

{
  "name": "mcpx-openai-chat",
  "version": "1.0.0",
  "type": "module",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@dylibso/mcpx-openai": "^0.0.2",
    "openai": "^4.77.3",
    "pino": "^9.6.0",
    "pino-pretty": "^13.0.0"
  }
}

Node version is: v21.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions