medusajs/medusa · warning
ts-node cannot be loaded and used, if you are running in pro
Error message
ts-node cannot be loaded and used, if you are running in production don't forget to set your NODE_ENV to production
What it means
The medusa-cli entry script tries to register ts-node and tsconfig-paths so it can run TypeScript source and resolve path aliases. If those modules are missing from node_modules (typically after a partial install or when a global install lacks devDependencies), it warns in non-production environments and falls back, which may cause later module-not-found errors for TS files or path aliases.
Source
Thrown at packages/cli/medusa-cli/cli.js:9
#!/usr/bin/env node
try {
require("ts-node").register({})
require("tsconfig-paths").register({})
} catch (e) {
const isProduction = process.env.NODE_ENV === "production"
if (!isProduction) {
console.warn(
"ts-node cannot be loaded and used, if you are running in production don't forget to set your NODE_ENV to production"
)
console.warn(e)
}
}
require("dotenv").config()
require("./dist/index.js")
View on GitHub (pinned to 5e06e544a2)
Solutions
- Set NODE_ENV=production when running in production so the warning is suppressed and behavior is expected
- Ensure ts-node and tsconfig-paths are installed: npm/yarn install with devDependencies included
- Prefer running the project-local medusa binary (npx medusa / yarn medusa) rather than a global install
Example fix
# before medusa start # after (production) NODE_ENV=production medusa start
Defensive patterns
Strategy: fallback
Validate before calling
if (process.env.NODE_ENV !== "production" && !require.resolve("ts-node", { paths: [process.cwd()] })) {
console.warn("ts-node missing — run a full install with devDependencies")
} Prevention
- Always set NODE_ENV=production in deployed environments
- Install the CLI locally in the project rather than globally so devDependencies resolve
When it happens
Trigger: Requiring ts-node or tsconfig-paths throws MODULE_NOT_FOUND because they were pruned from node_modules (e.g. production install) while NODE_ENV is not set to production.
Common situations: Running a globally installed medusa CLI against a project; NODE_ENV unset in a production deployment; yarn install --production pruning devDependencies.
Related errors
- Warning: could not parse ${candidate}, using default config
- Warning: could not read ${tsconfigBasePath}, using default c
- Failed to setup database; install PostgresQL or make sure to
- Lint produced ${result.warningCount} warning(s).
AI-assisted analysis of medusajs/medusa@5e06e544a2 (2026-08-27).
Data as JSON: /api/errors/b0db22fbc4670e05.
Report an issue: GitHub.