Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[bug]: Webpack / Typescript build issues #3784

Open
bennettl opened this issue Sep 20, 2024 · 3 comments
Open

[bug]: Webpack / Typescript build issues #3784

bennettl opened this issue Sep 20, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@bennettl
Copy link

Description

webpack is preventing the app from compiling due to type issues with the algoliasearch package

Language

JavaScript

Client

All

Steps to reproduce

I have the following relevant package dependencies

"typescript": "^4.7.4"
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
 "algoliasearch": "^5.4.1",
"@nestjs/core": "^9.0.0",
...

And executed my backend with nest start --watch and contain the follow errors (on the relvant log output)

Here is my TS Config

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "es2021",
    "lib": [
      "es2021"
    ],
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "skipLibCheck": true,
    "strictNullChecks": false,
    "noImplicitAny": false,
    "strictBindCallApply": false,
    "forceConsistentCasingInFileNames": false,
    "noFallthroughCasesInSwitch": false,
    "paths": {
      "@app/cache": [
        "libs/cache/src"
      ],
      "@app/cache/*": [
        "libs/cache/src/*"
      ],
      "@app/auth": [
        "libs/auth/src"
      ],
      "@app/auth/*": [
        "libs/auth/src/*"
      ],
      "@app/interceptors": [
        "libs/interceptors/src"
      ],
      "@app/interceptors/*": [
        "libs/interceptors/src/*"
      ],
      "@app/analytics": [
        "libs/analytics/src"
      ],
      "@app/analytics/*": [
        "libs/analytics/src/*"
      ],
      "@app/encrypt": [
        "libs/encrypt/src"
      ],
      "@app/encrypt/*": [
        "libs/encrypt/src/*"
      ],
      "@app/geolocation": [
        "libs/geolocation/src"
      ],
      "@app/geolocation/*": [
        "libs/geolocation/src/*"
      ]
    }
  }
}

Relevant log output

ERROR in /api/node_modules/@algolia/client-common/src/types/cache.ts
55:17-24
[tsl] ERROR in /api/node_modules/@algolia/client-common/src/types/cache.ts(55,18)
      TS2304: Cannot find name 'Storage'.

ERROR in //api/node_modules/@algolia/client-common/src/cache/createBrowserLocalStorageCache.ts
4:15-22
[tsl] ERROR in /api/node_modules/@algolia/client-common/src/cache/createBrowserLocalStorageCache.ts(4,16)
      TS2304: Cannot find name 'Storage'.

ERROR in /api/node_modules/@algolia/client-common/src/cache/createBrowserLocalStorageCache.ts
8:25-32
[tsl] ERROR in. /api/node_modules/@algolia/client-common/src/cache/createBrowserLocalStorageCache.ts(8,26)
      TS2304: Cannot find name 'Storage'.

ERROR in/api/node_modules/@algolia/client-common/src/cache/createBrowserLocalStorageCache.ts
10:40-46
[tsl] ERROR in /api/node_modules/@algolia/client-common/src/cache/createBrowserLocalStorageCache.ts(10,41)
      TS2304: Cannot find name 'window'.

4 errors have detailed information that is not shown.
Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.

webpack 5.76.2 compiled with 4 errors in 16823 ms


### Self-service

- [ ] I'd be willing to fix this bug myself.
@bennettl bennettl added the bug Something isn't working label Sep 20, 2024
@bennettl bennettl changed the title [bug]: Typescript build issues [bug]: Webpack / Typescript build issues Sep 20, 2024
@algolia algolia deleted a comment Sep 20, 2024
@shortcuts
Copy link
Member

shortcuts commented Sep 20, 2024

Hey, thanks for opening the issue :)

The type issue seems to be related to the fact that your backend build resolves to our browser build, rather than the node one.

Do you have a minimal reproduction of your stack, or more information about your environment?

Also, can you confirm your un on algoliasearch 5.5.2?

edit: I just saw nestjs

@bennettl
Copy link
Author

Yes we are using NestJS and i ran

npm install --save algoliasearch

and on the package.json i see

"algoliasearch": "^5.5.3"

Is there something special i need to do resolve this to node build?

@shortcuts
Copy link
Member

I think you need to hint webpack directly, with something like https://webpack.js.org/configuration/resolve/#resolveexportsfields

I don't get why nest resolves to the browser build, we default everything to node unless unspecified. I don't know nest enough to help debug the installation, @Fluf22 any idea?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants