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

Cannot find module '@adminjs/typeorm' or its corresponding type declarations. #61

Open
Paroca72 opened this issue Jun 28, 2023 · 9 comments

Comments

@Paroca72
Copy link

Hello,

I already seen something similar in the "closed" issues where is a workaround but not a solution.
Is possible to find a solution for this issue.

1

Node.js v18.16.0

Package,json

{
  "type": "module",
  "dependencies": {
    "@adminjs/typeorm": "^5.0.0",
    "@adminjs/express": "^6.0.0",
    "@types/express": "^4.17.17",
    "@types/express-session": "^1.17.7",
    "adminjs": "^7.0.6",
    "connect-typeorm": "^2.0.0",
    "express": "^4.18.2",
    "express-formidable": "^1.2.0",
    "express-session": "^1.17.3",
    "mssql": "^9.1.1",
    "reflect-metadata": "^0.1.13",
    "ts-node": "^10.9.1",
    "typeorm": "^0.3.17",
    "typescript": "^5.1.3"
  }
}

tsconfig.json

{
    "compilerOptions": {
        "module": "ESNext",
        "esModuleInterop": true,
        "target": "ESNext",
        "moduleResolution": "Node",
        "outDir": "dist",
        "forceConsistentCasingInFileNames": true,
        "noFallthroughCasesInSwitch": true,
        "isolatedModules": false,
        "strict": true,
        "noImplicitAny": true,
        "useUnknownInCatchVariables": false,
        "inlineSourceMap": true,
        "experimentalDecorators": true,
    },
    "ts-node": {
        "esm": true
    },
    "exclude": [
        "node_modules"
    ]
}

Thanks for your help
Sam

@dziraf
Copy link

dziraf commented Jun 28, 2023

        "moduleResolution": "Node",

has to be NodeNext or Node16 ("module" too)

@sbassin
Copy link

sbassin commented Jun 30, 2023

I tried those options for "moduleResolution" but the other AdminJS imports now give me a different error message:

The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an 
ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("@adminjs/express")' call 
instead.

I also tried the workaround described in the previous issue #60 and was still getting the error Cannot find module…. 🤔

@marina-eremina
Copy link

Downgrade to v.4 helped

@sbassin
Copy link

sbassin commented Jul 5, 2023

Downgrade to v.4 helped

I tried that as well and got a bit further, though I don't love that path since 5.0.0 has been out for two and half months with no patches to it. 😬

Either way, I'm having a lot of issues related to styled-components, which didn't seem to get added as a dependency when I installed AdminJS. Happy to create a separate issue if that's helpful, but I'm wondering if they're somehow related. 🤔

#0 8.254 node_modules/@adminjs/design-system/types/src/atoms/avatar/avatar.d.ts(6,58): error TS2694: Namespace '"node_modules/styled-components/dist/index"' has no exported member 'StyledComponent'.
#0 8.255 node_modules/@adminjs/design-system/types/src/atoms/button/button-css.d.ts(1,21): error TS2307: Cannot find module '@styled-components' or its corresponding type declarations.

@dziraf
Copy link

dziraf commented Jul 6, 2023

@sbassin most if not all of our commercial projects use @adminjs/typeorm and we've had no issues with typeorm/styled-components after migrating them to the latest versions. It's difficult to help without knowing other details regarding your project setup.

@sbassin
Copy link

sbassin commented Jul 9, 2023

I can appreciate that, @dziraf, and thanks for the reply. What information would be most helpful? I will freely admit to being quite inexperienced regarding many the tsconfig.json compiler settings. Here's what I have been trying in that file:

{
  "compilerOptions": {
    "rootDirs": ["./src", "./test"],
    "target": "ESNext",
    "types": ["node", "jest"],
    "forceConsistentCasingInFileNames": true,
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "strict": true,
    "outDir": "./dist",
    "sourceMap": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "strictPropertyInitialization": false,
    "baseUrl": ".",
    "paths": {
      "@/*": ["src/*"],
      "@test/*": ["test/*"],
      "@test-utils/*": ["test/util/*"],
      "@factories": ["factories"],
      "@factories/*": ["factories/*"],
      "@db/*": ["src/db/*"],
      "@models/*": ["src/models/*"],
      "@resolvers/*": ["src/resolvers/*"],
      "@services/*": ["src/services/*"]
    }
  }
}

And here are the dependencies in my package.json file:

  "dependencies": {
    "@adminjs/express": "^6.0.0",
    "@adminjs/typeorm": "^5.0.0",
    "@types/express-session": "^1.17.7",
    "adminjs": "^7.0.8",
    "apollo-server": "^3.12.0",
    "apollo-server-express": "^3.12.0",
    "auth0": "^3.4.0",
    "bcrypt": "^5.1.0",
    "chance": "^1.1.11",
    "class-validator": "^0.13.2",
    "express": "^4.18.2",
    "express-jwt": "^8.4.1",
    "express-oauth2-jwt-bearer": "^1.5.0",
    "gravatar": "^1.8.2",
    "jsonwebtoken": "^9.0.1",
    "module-alias": "^2.2.3",
    "pg": "^8.11.0",
    "postgres": "^3.3.5",
    "reflect-metadata": "^0.1.13",
    "styled-components": "^6.0.3",
    "tslog": "3.3.4",
    "type-graphql": "^1.1.1",
    "typedi": "^0.10.0",
    "typeorm": "^0.3.16"
  },

Would any more information be valuable?

@dziraf
Copy link

dziraf commented Jul 11, 2023

@sbassin do you have type: "module" set in your package.json?

@sbassin
Copy link

sbassin commented Jul 11, 2023

I do not, @dziraf, but I'd be happy to try that later tonight. Thanks.

@sbassin
Copy link

sbassin commented Jul 12, 2023

Well, that seems to have cleared up a lot of the problems I was seeing. I'm still seeing a number of these issues relating to @styled-components like:

node_modules/@adminjs/design-system/types/src/utils/reset.styles.d.ts:1:21 - error TS2307: Cannot find module '@styled-components' or its corresponding type declarations.

1 import { css } from '@styled-components';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants