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

[4.2 beta] - Error: Unknown dialect undefined on strapi app when start develop #13237

Closed
rodgeraraujo opened this issue May 4, 2022 · 96 comments · Fixed by #14521
Closed

[4.2 beta] - Error: Unknown dialect undefined on strapi app when start develop #13237

rodgeraraujo opened this issue May 4, 2022 · 96 comments · Fixed by #14521
Assignees
Labels
flag: EE Issues correlates to internal EE ticket issue: bug Issue reporting a bug severity: high If it breaks the basic use of the product source: typescript Source is related to TypeScript (typings, tooling, ...) status: confirmed Confirmed by a Strapi Team member or multiple community members

Comments

@rodgeraraujo
Copy link

Bug report

Required System information

  • Node.js version: v16.14.0
  • NPM version: 8.5.4
  • Strapi version: 4.2.0-beta.2
  • Database: postgres
  • Operating system: Mac OS (M1)

Describe the bug

When using the 4.2.0-beta.2 with typescript I get an error.

Steps to reproduce the behavior

  1. strapi develop
  2. See error

Expected behavior

Strapi start develop correctly.

Code snippets

> strapi develop

Building your admin UI with development configuration...
Admin UI built successfully
[2022-05-04 15:27:52.709] debug: ⛔️ Server wasn't able to start properly.
[2022-05-04 15:27:52.710] error: Unknown dialect undefined
Error: Unknown dialect undefined
    at getDialectClass (/Workspace/projects/project-name/node_modules/.pnpm/@strapi+database@4.2.0-beta.2_pg@8.7.3/node_modules/@strapi/database/lib/dialects/index.js:12:13)
    at getDialect (/Workspace/projects/project-name/node_modules/.pnpm/@strapi+database@4.2.0-beta.2_pg@8.7.3/node_modules/@strapi/database/lib/dialects/index.js:19:23)
    at new Database (/Workspace/projects/project-name/node_modules/.pnpm/@strapi+database@4.2.0-beta.2_pg@8.7.3/node_modules/@strapi/database/lib/index.js:27:20)
    at Function.Database.init (/Workspace/projects/project-name/node_modules/.pnpm/@strapi+database@4.2.0-beta.2_pg@8.7.3/node_modules/@strapi/database/lib/index.js:73:33)
    at Strapi.bootstrap (/Workspace/projects/project-name/node_modules/.pnpm/@strapi+strapi@4.2.0-beta.2_d1912f1bcfa17781bbbf94d8c8dc7418/node_modules/@strapi/strapi/lib/Strapi.js:385:30)
    at Strapi.load (/Workspace/projects/project-name/node_modules/.pnpm/@strapi+strapi@4.2.0-beta.2_d1912f1bcfa17781bbbf94d8c8dc7418/node_modules/@strapi/strapi/lib/Strapi.js:448:16)
    at async Strapi.start (/Workspace/projects/project-name/node_modules/.pnpm/@strapi+strapi@4.2.0-beta.2_d1912f1bcfa17781bbbf94d8c8dc7418/node_modules/@strapi/strapi/lib/Strapi.js:196:9)
 ELIFECYCLE  Command failed with exit code 1.

Additional context

When I use the version 4.2.0-beta.0 this issue does not happen and the project work as expected. But in versions 4.2.0-beta.1 and 4.2.0-beta.2 I have the same issue.

@maccomaccomaccomacco
Copy link
Contributor

Did you create the TypeScript project from zero?

@rodgeraraujo
Copy link
Author

Did you create the TypeScript project from zero?

Yes, was create from zero with TS, using version 4.2.0-beta.0 of Strapi.

@derrickmehaffy derrickmehaffy added this to To be reviewed (Open) in Developer Experience - Old via automation May 5, 2022
@sofyan-ahmad
Copy link

sofyan-ahmad commented May 6, 2022

Hey, I'm having a similar problem.
Any workaround?

It's only happening on Docker, everything works fine on my local

@derrickmehaffy derrickmehaffy removed this from To be reviewed (Open) in Developer Experience - Old May 6, 2022
@BANG88
Copy link

BANG88 commented May 27, 2022

Please help. we have the same issue on production env. It works as expected on local.

NODE_ENV=production yarn start

ENV:

Ubuntu 20
node v16.15.0
$ strapi version
4.2.0-beta.3

use PostgreSQL as database
image

@BANG88
Copy link

BANG88 commented May 27, 2022

Does anyone have a quick fixes for this please ? We will go to production this weekend. Please help.

Thank you very much.

@BANG88
Copy link

BANG88 commented May 27, 2022

I don't know what's the difference between running yarn develop and yarn start.

image

On production env we got a empty connection object.

image

@BANG88
Copy link

BANG88 commented May 27, 2022

@gu-stav Please help me. 😢

@derrickmehaffy
Copy link
Member

I'm going to lock this, please do not ping random people. v4.2 is a beta release and should only be for testing.

@strapi strapi locked and limited conversation to collaborators May 27, 2022
@maccomaccomaccomacco
Copy link
Contributor

Please help. we have the same issue on production env. It works as expected on local.

NODE_ENV=production yarn start

ENV:

Ubuntu 20
node v16.15.0
$ strapi version
4.2.0-beta.3

use PostgreSQL as database image

Thank you for taking the time for opening this issue.

We would need more information on this.
Could you provide the content of the tsconfig.json file?
Do you have a build folder in production? Does it contain the compiled code?

@strapi strapi unlocked this conversation May 30, 2022
@robertherber
Copy link

I'm getting this after upgrading from 4.2.0-beta3 to 4.2.0. Tried clearing .tmp/node_modules/.cache and rebuilding everything. Everything has been working great on the beta for the last few weeks. Any ideas?

@derrickmehaffy
Copy link
Member

I'm getting this after upgrading from 4.2.0-beta3 to 4.2.0. Tried clearing .tmp/node_modules/.cache and rebuilding everything. Everything has been working great on the beta for the last few weeks. Any ideas?

You will need to go to v4.3.0.beta as we didn't release typescript in v4.2.0 (it got delayed)

@robertherber
Copy link

robertherber commented Jun 16, 2022

I'm getting this after upgrading from 4.2.0-beta3 to 4.2.0. Tried clearing .tmp/node_modules/.cache and rebuilding everything. Everything has been working great on the beta for the last few weeks. Any ideas?

You will need to go to v4.3.0.beta as we didn't release typescript in v4.2.0 (it got delayed)

Ah, I see! Thanks for the info 👍

@derrickmehaffy Follow up question on that - when is the 4.3.0 stable release expected?

@derrickmehaffy
Copy link
Member

I'm getting this after upgrading from 4.2.0-beta3 to 4.2.0. Tried clearing .tmp/node_modules/.cache and rebuilding everything. Everything has been working great on the beta for the last few weeks. Any ideas?

You will need to go to v4.3.0.beta as we didn't release typescript in v4.2.0 (it got delayed)

Ah, I see! Thanks for the info +1

@derrickmehaffy Follow up question on that - when is the 4.3.0 stable release expected?

late July, I don't believe we have an exact date yet but it should be ~6 weeks after the release of v4.2.0

@maccomaccomaccomacco
Copy link
Contributor

This issue can't be reproduced in 4.3.0-beta.2 (the last beta supporting TypeScript). Waiting for confirmation and/or for some days before closing the issue.

@sepiette
Copy link

I just ran into this issue with 4.3.0-beta.2, but specifically for unit testing in CI environments. I was able to solve locally following the suggestions in this issue by adding

    await Strapi({ distDir: './dist' }).load(); 

With this tests run successfully.

However, in higher environments I am again getting the following error:
Screen Shot 2022-07-19 at 10 58 44 AM

@Convly
Copy link
Member

Convly commented Jul 25, 2022

Hey @sepiette, by any chance, do you have a minimal example I could use to reproduce the issue you're having? I fail to break it on my side 😕

@boazpoolman
Copy link
Contributor

I'm having this issue as wel. Happening on strapi develop.
All I did was install Strapi like npx create-strapi-app@latest strapi-4.3 selected "Typescript" and "Postgres" and ran the develop command.
Tested it with 4.3.0, 4.3.1 and 4.3.2. Each give me the same issue.

@TimFoerster
Copy link

TimFoerster commented Aug 3, 2022

With windows / development, when I run yarn build

$ strapi build
Starting the compilation for TypeScript files in ...\strapi43
Building your admin UI with development configuration...

√ Webpack
  Compiled successfully in 17.15s

Admin UI built successfully

ls dist

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        03.08.2022     18:10                build
d-----        03.08.2022     18:09                config
d-----        03.08.2022     18:09                data
d-----        03.08.2022     18:09                src
-a----        03.08.2022     18:09             19 tsconfig.tsbuildinfo

I receive a config folder.

When i run the same (even without NODE_ENV=production) on the server (Ubuntu 20.04.4 LTS (GNU/Linux 5.4.0 x86_64)) i'm missing config and data directory

xy@h:~/h$ yarn build
yarn run v1.22.19
$ strapi build
Starting the compilation for TypeScript files in ./
Building your admin UI with development configuration...

✔ Webpack
  Compiled successfully in 31.69s

Admin UI built successfully
u@h:~/h$ ls -l dist 

drwxr-xr-x 2 u ug 20480 Aug  3 18:08 build
drwxr-xr-x 4 u ug 4096 Aug  3 18:08 src
-rw-r--r-- 1 u ug 19 Aug  3 18:08 tsconfig.tsbuildinfo

Both with node v16.16.0

Copying dist/config to server and it worked.

Looks like this problem only occurs on unix systems?

Here you have a generic compiled config folder that you can include for testing:
config.zip

@TimFoerster
Copy link

This problem goes much deeper. None of the compiled .ts files can be found in the dist directory. for example in src/api/model not a single controllers, routes, services directory exists.

@Convly
Copy link
Member

Convly commented Aug 4, 2022

I'm having this issue as wel. Happening on strapi develop. All I did was install Strapi like npx create-strapi-app@latest strapi-4.3 selected "Typescript" and "Postgres" and ran the develop command. Tested it with 4.3.0, 4.3.1 and 4.3.2. Each give me the same issue.

I tried reproducing your issue with your configuration but failed to do so
image

@Convly
Copy link
Member

Convly commented Aug 4, 2022

This problem goes much deeper. None of the compiled .ts files can be found in the dist directory. for example in src/api/model not a single controllers, routes, services directory exists.

I tried reproducing with your settings, but everything seems to be working normally on my side... I will need more information regarding your project to be able to help you there 😕
image

@TimFoerster
Copy link

@Convly I found the error. This is only the case, if the project contains a dot . for example project test.name results in missing .js files.

@exotexot
Copy link

exotexot commented Aug 4, 2022

Having the same issue. When running on local machine no problem. The problem only happens when using Docker and strap in development environment.

NO TypeScript!

Using Strapi 4.3.2
mysql 5.7
node 16-alpine

Also tried using a PostgresDB. Same behaviour.

@TimFoerster
Copy link

@exotexot what is the name of project directory?

@exotexot
Copy link

exotexot commented Aug 8, 2022

@TimFoerster I've seen your comment about project name. My project only contains a-z values, no special charachters

@kulak91
Copy link
Contributor

kulak91 commented Sep 26, 2022

Strapi 4.3.9, Windows 10. In file .\node_modules\@strapi\typescript-utils\lib\utils\get-config-path.js there is a line return configFilePath.startsWith(dirAbsolutePath) ? configFilePath : undefined; near end of file. Problem is that dirAbsolutePath uses Windows notation (backslashes) but configFilePath uses notation with ordinal slashes, therefore Typescript is never detected. Not sure that it is a root cause of the problem, but changing first occurrence of configFilePath on that line to path.resolve(configFilePath) fixed the issue for me.

Thank you! return path.resolve(configFilePath).startsWith(dirAbsolutePath) ? configFilePath : undefined; worked for me

@strapi-bot
Copy link

This issue has been mentioned on Strapi Community Forum. There might be relevant details there:

https://forum.strapi.io/t/strapi-v4-3-9-will-run-as-typescript/22356/5

@South-Paw
Copy link

@st33v3 legend 👍

First time using Strapi tonight in a fair while and bit shocked that the TypeScript setup didn't work out the box...

@abeljrgit
Copy link

Typescript strapi is not working as of September 28, 2022. Javascript strapi is working. I used postgres as my database. Same error as the above.

@gorden0929
Copy link

The fix is going on but no update.
For more detail: #14088

@antokhio
Copy link

it's in this state for months

@sinamoradi1375
Copy link

Is this problem ever gonna get any attention?

@South-Paw
Copy link

South-Paw commented Oct 2, 2022

Have found a few other duplicate issues and referenced them to this.

Apologies, know I'm being a pain but I find it funny that some other issues (#14305, #14306) have been closed and marked as duplicates of this issue, but this issue, despite being marked "high priority" has not been progressed nor has the PR to fix it 😆

Hopefully making some noise will get those gears spinning again 👍

@ecosse3
Copy link

ecosse3 commented Oct 2, 2022

The same issue to me while deploying production to render.com. After second/third try app is started.

image

I am not sure if database.ts config is related to this. I'm using pg-connection-string instead of the default approach.

@SoulEvans07
Copy link

@st33v3 and @kulak91 seem to be correct. My "temporary" solution is to use patch-package with the following patch file patches.zip

@Bassel17 Bassel17 linked a pull request Oct 4, 2022 that will close this issue
@andreiwow2
Copy link

I can't get it to work on Centos 8, I have same issue saying Unknown dialect undefined, but it works on my laptop Macos

@chrizvo
Copy link

chrizvo commented Nov 25, 2022

@andreiwow2 have you already fixed your problem? Because i have the same issue with cent os 7

@onursagir
Copy link

@chrizvo do you have a tsconfig.json file?

@Dupflo
Copy link

Dupflo commented Dec 15, 2022

I ran a similar issue on Strapi 4.4.7 Typescript with a custom server.js file to inject Azure Key Vault Keys

@sunderee
Copy link

Similar issue on Strapi 4.5.4, using TypeScript.

Here's the Dockerfile:

# --- BUILDER STAGE --- #
FROM alpine:latest AS builder

RUN apk --no-cache --update add nodejs npm bash curl
RUN curl -sf https://gobinaries.com/tj/node-prune | sh

WORKDIR /usr/src/app
COPY package.json .
RUN npm install

COPY . .
RUN npm run build:production

RUN rm -rf node_modules && npm install --omit=dev && node-prune

# --- RUNNER STAGE --- #
FROM alpine:latest AS runner
RUN apk --no-cache --update add nodejs npm

WORKDIR /usr/src/app
COPY --from=builder /usr/src/app/.env .env
COPY --from=builder /usr/src/app/dist ./dist
COPY --from=builder /usr/src/app/node_modules ./node_modules
COPY --from=builder /usr/src/app/config ./config
COPY --from=builder /usr/src/app/database ./database
COPY --from=builder /usr/src/app/public ./public
COPY --from=builder /usr/src/app/package.json ./package.json

# Run it!
EXPOSE 1337
CMD [ "npm", "run", "start:production" ]

here is the docker-compose.yaml:

version: '3'
services:
  strapi:
    build: .
    ports:
      - "1337:1337"
    environment:
      DATABASE_CLIENT: postgres
      DATABASE_HOST: db
      DATABASE_PORT: 5432
      DATABASE_NAME: strapi
      DATABASE_USERNAME: strapi
      DATABASE_PASSWORD: strapi
    depends_on:
      - db
  
  db:
    image: postgres
    environment:
      POSTGRES_USER: strapi
      POSTGRES_PASSWORD: strapi
      POSTGRES_DB: strapi
    volumes:
      - pgdata:/var/lib/postgresql/data

volumes:
  pgdata:

And this is the database.ts file:

export default ({ env }) => ({
  connections: {
    default: {
      connector: "bookshelf",
      settings: {
        client: "postgres",
        host: env("DATABASE_HOST"),
        port: env.int("DATABASE_PORT"),
        database: env("DATABASE_NAME"),
        username: env("DATABASE_USERNAME"),
        password: env("DATABASE_PASSWORD"),
        ssl: env.bool("DATABASE_SSL", false),
      },
      options: {
        pool: {
          min: 0,
          max: 15,
          idleTimeoutMillis: 30000,
          createTimeoutMillis: 30000,
          acquireTimeoutMillis: 30000,
        },
      },
    },
  },
});

@onursagir
Copy link

@sunderee in your Dockerfile try copying over your tsconfig.json

@sunderee
Copy link

@sunderee in your Dockerfile try copying over your tsconfig.json

Just tried, same result. I'm migrating a project to JavaScript; and that seems to be working just fine. The only difference is that the output folder is build, not dist.

@derrickmehaffy
Copy link
Member

build is the output folder of the admin, dist is the output folder of the entire project (TS -> JS)

@nazirov91
Copy link

I had the same issue recently. The word underfied in error: Unknown dialect undefined was directly coming from the DATABASE_CLIENT of my .env file.

  • If you .env, make sure the value for DATABASE_CLIENT is correct. In my case I put 'postgres'

  • in config/database.ts. make sure the value for client is given like this const client = env("DATABASE_CLIENT", "postgres");

  • Make sure DB name, user name and passwords are correct. You should try to connect to the db and ensure it works

  • And most importantly, remove your .cache and dist folders. And rebuild the strapi by running strapi build

After that the issue should be resolved. At least it was resolved for me.
I hope this helps someone with similar issue.

@Vanshita0771
Copy link

Building your admin UI with development configuration...
Admin UI built successfully
[2023-03-31 09:01:10.506] debug: ⛔️ Server wasn't able to start properly.
[2023-03-31 09:01:10.510] error: Unknown dialect undefined
Error: Unknown dialect undefined
at getDialectClass (C:\Users\Admin\OneDrive\Desktop\Strapi\server\server\node_modules@strapi\database\lib\dialects\index.js:12:13)
at getDialect (C:\Users\Admin\OneDrive\Desktop\Strapi\server\server\node_modules@strapi\database\lib\dialects\index.js:19:23)
at new Database (C:\Users\Admin\OneDrive\Desktop\Strapi\server\server\node_modules@strapi\database\lib\index.js:31:20)
at Database.init (C:\Users\Admin\OneDrive\Desktop\Strapi\server\server\node_modules@strapi\database\lib\index.js:116:14)
at Strapi.bootstrap (C:\Users\Admin\OneDrive\Desktop\Strapi\server\server\node_modules@strapi\strapi\lib\Strapi.js:413:30)
at Strapi.load (C:\Users\Admin\OneDrive\Desktop\Strapi\server\server\node_modules@strapi\strapi\lib\Strapi.js:484:16)
at async Strapi.start (C:\Users\Admin\OneDrive\Desktop\Strapi\server\server\node_modules@strapi\strapi\lib\Strapi.js:215:9)

How to resolve it?

@DevDengChao
Copy link

I solved a similar issue when running strapi start on production env by debugging the command.

If you are starting a Typescript project, you should follow the Start strapi programmatically section in TypeScript | Strapi Documentation .
Otherwise you have to deploy tsconfig.json file and src and config dirs together with the dist dir to production env if you try to start it with strapi start.

This is because the @strapi/typescript-utils/lib/utils/is-using-typescript uses the tsconfig.json file to determine whether you are starting a Typescript project or a Javascript project when running strapi start.

Hope this helps you guys.

@idolgoff
Copy link

idolgoff commented Sep 2, 2023

I solved a similar issue when running strapi start on production env by debugging the command.

If you are starting a Typescript project, you should follow the Start strapi programmatically section in TypeScript | Strapi Documentation . Otherwise you have to deploy tsconfig.json file and src and config dirs together with the dist dir to production env if you try to start it with strapi start.

This is because the @strapi/typescript-utils/lib/utils/is-using-typescript uses the tsconfig.json file to determine whether you are starting a Typescript project or a Javascript project when running strapi start.

Hope this helps you guys.

Hey man!
I've spent to many nights trying to figure out why my typescript version doesn't want to run inside docker!
It such an unobvious case!.. Thanks a lot, you've saved my life and my weekend )

Just added this
COPY ./tsconfig.json ./tsconfig.json

It works now

@antonAtGit
Copy link

antonAtGit commented Nov 11, 2023

I have the same problems with strapi running on linux server in production mode.

use volumes and dont bind folder. check your config, src, etc folders on the server. Everything is empty in my case.
I changed my compose file settings to volumes and it works.

...
volumes:
- strapi-config:/opt/app/config
- strapi-src:/opt/app/src
- strapi-env:/opt/app/.env
...

hope that helps somebody

@karatekaneen
Copy link

karatekaneen commented Nov 28, 2023

I solved this issue by starting Strapi from a node script instead:

// server.js
const strapi = require("@strapi/strapi");
strapi({ distDir: "./dist" }).start();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flag: EE Issues correlates to internal EE ticket issue: bug Issue reporting a bug severity: high If it breaks the basic use of the product source: typescript Source is related to TypeScript (typings, tooling, ...) status: confirmed Confirmed by a Strapi Team member or multiple community members
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.