strapi
strapi copied to clipboard
Updating from 4.3.2 to 4.3.4, cannot read property 'push' of undefined
Cannot read property 'push' of undefined
Required System information
- Node.js version: 15.8.0
- NPM version: 7.5.1
- Strapi version: 4.3.4
- Database: postgres
- Operating system: Windows
Describe the bug
When starts appears this error:
[2022-08-11 19:31:20.232] error: Cannot read property 'push' of undefined
TypeError: Cannot read property 'push' of undefined
at Object.addCreateLocalizationAction (C:\Users\osiri\devprojects\strapi-project\node_modules\@strapi\plugin-i18n\server\services\core-api.js:182:48)
at C:\Users\osiri\devprojects\strapi-project\node_modules\@strapi\plugin-i18n\server\register.js:78:22
at Array.forEach (<anonymous>)
at extendLocalizedContentTypes (C:\Users\osiri\devprojects\strapi-project\node_modules\@strapi\plugin-i18n\server\register.js:56:38)
at Object.module.exports [as register] (C:\Users\osiri\devprojects\strapi-project\node_modules\@strapi\plugin-i18n\server\register.js:12:3)
at Object.register (C:\Users\osiri\devprojects\strapi-project\node_modules\@strapi\strapi\lib\core\domain\module\index.js:47:46)
at Object.register (C:\Users\osiri\devprojects\strapi-project\node_modules\@strapi\strapi\lib\core\registries\modules.js:33:19)
at async Strapi.runLifecyclesFunctions (C:\Users\osiri\devprojects\strapi-project\node_modules\@strapi\strapi\lib\Strapi.js:510:5)
at async Strapi.register (C:\Users\osiri\devprojects\strapi-project\node_modules\@strapi\strapi\lib\Strapi.js:379:5)
at async Strapi.load (C:\Users\osiri\devprojects\strapi-project\node_modules\@strapi\strapi\lib\Strapi.js:456:5)
error Command failed with exit code 1.
Steps to reproduce the behavior
- Changes in package json from:
"@strapi/plugin-i18n": "4.3.0",
"@strapi/plugin-users-permissions": "4.3.0",
"@strapi/strapi": "4.3.2",
to
"@strapi/plugin-i18n": "4.3.3",
"@strapi/plugin-users-permissions": "4.3.3",
"@strapi/strapi": "4.3.4",
- remove node_modules, package-lock.json, and yarn.lock
- yarn
- yarn develop
Expected behavior
Starts correctly
I'm not able to reproduce this. Upgrading from v4.3.2 => v4.3.4 following the outlined steps works correctly for me. I noticed you have set @strapi/plugin-users-permissions and @strapi/plugin-i18n to use 4.3.3. Does this still persist if you change those to 4.3.4 ? I tested both implementations and was not able to reproduce.
Are you able to reproduce if you do a fresh install of v4.3.2 and try to run the upgrade you've outlined from the new project?
I also tested and cannot reproduce :thinking:
I got the same problem after upgrading from 4.3.2 to 4.3.3
I got the same problem after upgrading from 4.3.3 to 4.3.4
Can you please provide some more information on ways to reproduce this?
$ strapi develop
[2022-08-12 12:53:38.669] debug: βοΈ Server wasn't able to start properly.
[2022-08-12 12:53:38.671] error: Cannot read properties of undefined (reading 'push')
TypeError: Cannot read properties of undefined (reading 'push')
at Object.addCreateLocalizationAction (C:\wamp64\www\saigoneer-apps\un-apps\urbanist-travel\cms-strapi-v4-ts\node_modules\@strapi\plugin-i18n\server\services\core-api.js:182:48)
at C:\wamp64\www\saigoneer-apps\un-apps\urbanist-travel\cms-strapi-v4-ts\node_modules\@strapi\plugin-i18n\server\register.js:78:22
at Array.forEach (<anonymous>)
at extendLocalizedContentTypes (C:\wamp64\www\saigoneer-apps\un-apps\urbanist-travel\cms-strapi-v4-ts\node_modules\@strapi\plugin-i18n\server\register.js:56:38)
at Object.module.exports [as register] (C:\wamp64\www\saigoneer-apps\un-apps\urbanist-travel\cms-strapi-v4-ts\node_modules\@strapi\plugin-i18n\server\register.js:12:3)
at Object.register (C:\wamp64\www\saigoneer-apps\un-apps\urbanist-travel\cms-strapi-v4-ts\node_modules\@strapi\strapi\lib\core\domain\module\index.js:47:46)
at Object.register (C:\wamp64\www\saigoneer-apps\un-apps\urbanist-travel\cms-strapi-v4-ts\node_modules\@strapi\strapi\lib\core\registries\modules.js:33:19)
at async Strapi.runLifecyclesFunctions (C:\wamp64\www\saigoneer-apps\un-apps\urbanist-travel\cms-strapi-v4-ts\node_modules\@strapi\strapi\lib\Strapi.js:510:5)
at async Strapi.register (C:\wamp64\www\saigoneer-apps\un-apps\urbanist-travel\cms-strapi-v4-ts\node_modules\@strapi\strapi\lib\Strapi.js:379:5)
at async Strapi.load (C:\wamp64\www\saigoneer-apps\un-apps\urbanist-travel\cms-strapi-v4-ts\node_modules\@strapi\strapi\lib\Strapi.js:456:5)
at async Strapi.start (C:\wamp64\www\saigoneer-apps\un-apps\urbanist-travel\cms-strapi-v4-ts\node_modules\@strapi\strapi\lib\Strapi.js:198:9)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
* The terminal process "C:\Program Files\Git\bin\bash.exe '--login', '-c', 'yarn run develop'" terminated with exit code: 1.
* Terminal will be reused by tasks, press any key to close it.
Windows 10 Node.js version: 16.16 yarn v1.22.18
"sqlite3": "5.0.11", "@strapi/plugin-users-permissions": "4.3.4", "@strapi/plugin-i18n": "4.3.4", "@strapi/strapi": "4.3.4", "@strapi/plugin-graphql": "^4.3.4", "@strapi/plugin-i18n": "4.3.4",
One more detail: I remember that this project started as a 4.3.0Beta (Typescript), I have another one that began in previous versions (no TS) and then updated to the most recent one. I don't have this issue, in the same environment.
I'm still not able to reproduce this specific error message, however, starting a new project on v4.3.2 using the typescript flag and following the above steps does end up in a different error for me:
error TS18003: No inputs were found in config file <USERPATH>/strapi_v4.3.2_ts/tsconfig.json'.
Specified 'include' paths were '["./","src/**/*.json"]' and 'exclude' paths were '["node_modules/","build/","dist/",".cache/",".tmp/","src/admin/","**/*.test.ts","src/plugins/**"]'.
Found 1 error(s).
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Do either of you @galago or @biko8 have access to a non-Windows machine (or even try running WSL)? That is the only common denominator I can see
Can the inability to reproduce some issues be related to a plain updating trial without any entities created on the old versions? Haven't seen Strapi internals, but I suspect that if there where some model changes, upgrading a populated installation to a new version will most likely go with errors if there's no entity attribute checking.
Can the inability to reproduce some issues be related to a plain updating trial without any entities created on the old versions? Haven't seen Strapi internals, but I suspect that if there where some model changes, upgrading a populated installation to a new version will most likely go with errors if there's no entity attribute checking.
Normally it's not a problem as we generally handle that migration automatically but in the case where some manual steps are required then we document them in: https://docs.strapi.io/developer-docs/latest/update-migration-guides/migration-guides.html#v4-migration-guides
I also have the same issue, happened when trying to update from 4.3.0 to 4.3.4
no change after installing 4.3.6. Still the same error
Can any of you try reproducing this on a fresh project and try working through the migrations?
same bug on fresh installation https://github.com/a-witkowski/test-strapi
node: v16.15.1 windows: 10 database: postgres
yarn develop
yarn run v1.22.15
$ strapi develop
Building your admin UI with development configuration...
Admin UI built successfully
[2022-08-30 21:55:51.090] debug: βοΈ Server wasn't able to start properly.
[2022-08-30 21:55:51.092] error: Unknown dialect undefined
Error: Unknown dialect undefined
at getDialectClass (D:\projects\test-strapi\node_modules\@strapi\database\lib\dialects\index.js:12:13)
at getDialect (D:\projects\test-strapi\node_modules\@strapi\database\lib\dialects\index.js:19:23)
at new Database (D:\projects\test-strapi\node_modules\@strapi\database\lib\index.js:27:20)
at Function.Database.init (D:\projects\test-strapi\node_modules\@strapi\database\lib\index.js:77:35)
at Strapi.bootstrap (D:\projects\test-strapi\node_modules\@strapi\strapi\lib\Strapi.js:392:30)
at Strapi.load (D:\projects\test-strapi\node_modules\@strapi\strapi\lib\Strapi.js:457:16)
at async Strapi.start (D:\projects\test-strapi\node_modules\@strapi\strapi\lib\Strapi.js:198:9)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Same problem here. Last working Strapi version is 4.3.2, but since then I cannot upgrade to newer version because of this error.
yarn run v1.22.19
$ strapi develop
[2022-09-08 07:44:15.472] debug: βοΈ Server wasn't able to start properly.
[2022-09-08 07:44:15.474] error: Cannot read properties of undefined (reading 'push')
TypeError: Cannot read properties of undefined (reading 'push')
at Object.addCreateLocalizationAction (C:\Repo\strapi-project\node_modules\@strapi\plugin-i18n\server\services\core-api.js:186:48)
at C:\Repo\strapi-project\node_modules\@strapi\plugin-i18n\server\register.js:78:22
at Array.forEach (<anonymous>)
at extendLocalizedContentTypes (C:\Repo\strapi-project\node_modules\@strapi\plugin-i18n\server\register.js:56:38)
at Object.module.exports [as register] (C:\Repo\strapi-project\node_modules\@strapi\plugin-i18n\server\register.js:12:3)
at Object.register (C:\Repo\strapi-project\node_modules\@strapi\strapi\lib\core\domain\module\index.js:47:46)
at Object.register (C:\Repo\strapi-project\node_modules\@strapi\strapi\lib\core\registries\modules.js:33:19)
at async Strapi.runLifecyclesFunctions (C:\Repo\strapi-project\node_modules\@strapi\strapi\lib\Strapi.js:510:5)
at async Strapi.register (C:\Repo\strapi-project\node_modules\@strapi\strapi\lib\Strapi.js:379:5)
at async Strapi.load (C:\Repo\strapi-project\node_modules\@strapi\strapi\lib\Strapi.js:456:5)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
My specs: Strapi 4.3.8 TypeScript (same error on 4.3.4, 4.3.6, but not on 4.3.2) DB: PostgreSQL Windows 11 Node 16.17.0 Yarn v1.22.19
I've tried to understand this problem by going to addCreateLocalizationAction function located in node_modules@strapi\plugin-i18n\server\services\core-api.js:186:48, which looks like this:
/**
* Adds a route & an action to the core api controller of a content type to allow creating new localizations
* @param {object} contentType
*/
const addCreateLocalizationAction = (contentType) => {
const { modelName, apiName } = contentType;
const localizationRoute = createLocalizationRoute(contentType);
strapi.api[apiName].routes[modelName].routes.push(localizationRoute);
strapi.container.get('controllers').extend(`api::${apiName}.${modelName}`, (controller) => {
return Object.assign(controller, {
createLocalization: createLocalizationHandler(contentType),
});
});
};
From what I understand, my project has a model that uses i18n, and extending the model with functions to create new locations fails because the object contained under strapi.api[apiName].routes[modelName] does not have a routes field. Therefore, calling the push method ends with the error "Cannot read properties of undefined (reading 'push')."
BTW. the localizationRoute object before this error looks like the following, if that helps any (I put console.log before the push function call)
{
method: 'POST',
path: '/articles/:id/localizations',
handler: 'article.createLocalization',
config: { policies: [] }
}
I was going to create reproducible repository with Strapi 4.3.8, but on a fresh project with PostgreSQL I'm getting same error as @a-witkowski
yarn run v1.22.19
$ strapi develop
Building your admin UI with development configuration...
Admin UI built successfully
[2022-09-08 08:16:55.758] debug: βοΈ Server wasn't able to start properly.
[2022-09-08 08:16:55.761] error: Unknown dialect undefined
Error: Unknown dialect undefined
at getDialectClass (C:\Repo\strapi-i18n-error\node_modules\@strapi\database\lib\dialects\index.js:12:13)
at getDialect (C:\Repo\strapi-i18n-error\node_modules\@strapi\database\lib\dialects\index.js:19:23)
at new Database (C:\Repo\strapi-i18n-error\node_modules\@strapi\database\lib\index.js:27:20)
at Function.Database.init (C:\Repo\strapi-i18n-error\node_modules\@strapi\database\lib\index.js:77:35)
at Strapi.bootstrap (C:\Repo\strapi-i18n-error\node_modules\@strapi\strapi\lib\Strapi.js:392:30)
at Strapi.load (C:\Repo\strapi-i18n-error\node_modules\@strapi\strapi\lib\Strapi.js:457:16)
at async Strapi.start (C:\Repo\strapi-i18n-error\node_modules\@strapi\strapi\lib\Strapi.js:198:9)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Sounds like you are hitting this issue now: https://github.com/strapi/strapi/issues/13237 which is a known TS issue on windows.
I'm still not able to reproduce this specific error message, however, starting a new project on
v4.3.2using thetypescriptflag and following the above steps does end up in a different error for me:error TS18003: No inputs were found in config file <USERPATH>/strapi_v4.3.2_ts/tsconfig.json'. Specified 'include' paths were '["./","src/**/*.json"]' and 'exclude' paths were '["node_modules/","build/","dist/",".cache/",".tmp/","src/admin/","**/*.test.ts","src/plugins/**"]'. Found 1 error(s). error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.Do either of you @galago or @biko8 have access to a non-Windows machine (or even try running WSL)? That is the only common denominator I can see
I tested in a MacBook and it works well, seems a bug inside Windows.
Same error running the test while following the official doc.
TypeError: Cannot read properties of undefined (reading 'push')
6 | async function setupStrapi() {
7 | if (!instance) {
> 8 | await Strapi().load();
| ^
9 | instance = strapi;
10 |
11 | await instance.server.mount();
at Object.addCreateLocalizationAction (node_modules/@strapi/plugin-i18n/server/services/core-api.js:184:48)
at node_modules/@strapi/plugin-i18n/server/register.js:78:22
at Array.forEach (<anonymous>)
at extendLocalizedContentTypes (node_modules/@strapi/plugin-i18n/server/register.js:56:38)
at Object.<anonymous>.module.exports [as register] (node_modules/@strapi/plugin-i18n/server/register.js:12:3)
at Object.register (node_modules/@strapi/strapi/lib/core/domain/module/index.js:47:46)
at Object.register (node_modules/@strapi/strapi/lib/core/registries/modules.js:33:19)
at Strapi.runLifecyclesFunctions (node_modules/@strapi/strapi/lib/Strapi.js:528:5)
at Strapi.register (node_modules/@strapi/strapi/lib/Strapi.js:393:5)
at Strapi.load (node_modules/@strapi/strapi/lib/Strapi.js:474:5)
at setupStrapi (tests/helpers/strapi.js:8:9)
at Object.<anonymous> (tests/app.test.js:5:5)
I see get the error above when running jest tests as well inside a Typescript project
Hello!
As we have not received any new or updated information to reproduce this issue in the last 14 days we are marking this issue as closed. Should you have new information please feel free to respond and we will consider reopening it.
If anyone else have updated information for this issue, please open up a new bug report and simply reference this closed bug report so that we can get any new information you may have. If you have questions please refer to the contributor's guide on opening issues.
Thank you and have a great day!
I am having the same issue when I try to run jest tests from the official https://docs.strapi.io/dev-docs/testing link
yarn run v1.22.19 $ jest --forceExit --detectOpenHandles FAIL tests/app.test.js β strapi is defined
β strapi is defined
TypeError: Cannot read properties of undefined (reading 'forEach')
6 | async function setupStrapi() {
7 | if (!instance) {
> 8 | await Strapi().load();
| ^
9 | instance = strapi;
10 |
11 | await instance.server.mount();
at node_modules/@strapi/strapi/lib/services/server/register-routes.js:98:21
at node_modules/lodash/lodash.js:4967:15
at baseForOwn (node_modules/lodash/lodash.js:3032:24)
at node_modules/lodash/lodash.js:4936:18
at Function.forEach (node_modules/lodash/lodash.js:9410:14)
at registerAPIRoutes (node_modules/@strapi/strapi/lib/services/server/register-routes.js:94:7)
at Object.<anonymous>.module.exports (node_modules/@strapi/strapi/lib/services/server/register-routes.js:25:3)
at Object.initRouting (node_modules/@strapi/strapi/lib/services/server/index.js:96:13)
at Strapi.bootstrap (node_modules/@strapi/strapi/lib/Strapi.js:475:23)
at Strapi.load (node_modules/@strapi/strapi/lib/Strapi.js:488:5)
at setupStrapi (tests/helpers/strapi.js:8:5)
at Object.<anonymous> (tests/app.test.js:6:3)
Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total Time: 1.858 s, estimated 2 s Ran all test suites. error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
I am also having the same problem, following the docs and installing ts-jest, although i get a slightly different error message
TypeError: Cannot read properties of undefined (reading 'push')
After some digging through the source code I have found a solution for anyone else struggling with this. You have to define distDir in the options for strapi like so:
await Strapi({
distDir: "dist",
}).load();
instead of
await Strapi().load();
If anyone knows who to tag to update the docs, please do
Actually, this https://github.com/qunabu/strapi-unit-test-example/tree/ver4ts helped me a lot.
@Alexnortung probably will be interesting for you as well.