pulumi / pulumi

Pulumi - Infrastructure as Code in any programming language 🚀
https://www.pulumi.com
Apache License 2.0
21.95k stars 1.13k forks source link

Pulumi errors on not finding "mapValues" in lodash package #13320

Open MitchellGerdisch opened 1 year ago

MitchellGerdisch commented 1 year ago

What happened?

I did the following:

I received this error:

Diagnostics:
  pulumi:pulumi:Stack (lodash-github-issue-dev):
    error: Running program '/Users/mitch/Downloads/lodash-stuff/lodash-github-issue/' failed with an unhandled exception:
    TSError: ⨯ Unable to compile TypeScript:
    index.ts(2,21): error TS2305: Module '"../../../../../Users/mitch/Downloads/lodash-stuff/lodash-github-issue/node_modules/@types/lodash"' has no exported member 'mapValues'.

If I then do the following things will be fine:

Expected Behavior

I shouldn't have to go through this sequence to be able to use the lastest version of the types package.

Steps to reproduce

See above

Output of pulumi about

CLI
Version 3.73.0 Go Version go1.20.5 Go Compiler gc

Plugins NAME VERSION nodejs unknown

Host
OS darwin Version 13.4.1 Arch x86_64

This project is written in nodejs: executable='/Users/mitch/.nvm/versions/node/v18.0.0/bin/node' version='v18.0.0'

Current Stack: xxxxxx/lodash-test/dev

Found no resources associated with dev

Found no pending operations associated with dev

Backend
Name pulumi.com

Dependencies: NAME VERSION @pulumi/pulumi 3.73.0 @types/lodash 4.14.195 @types/node 16.18.37 lodash 4.17.21

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

justinvp commented 1 year ago

I don't think this issue is specific to Pulumi. I can repro without using anything related to Pulumi.

package.json

{
    "name": "lodashrepro",
    "main": "index.ts",
    "devDependencies": {
        "@types/node": "^16"
    },
    "dependencies": {
        "@types/lodash": "^4.14.195",
        "lodash": "^4.17.21",
        "ts-node": "^7.0.1",
        "typescript": "~3.8.3"
    }
}

tsconfig.json

{
    "compilerOptions": {
        "strict": true,
        "outDir": "bin",
        "target": "es2016",
        "module": "commonjs",
        "moduleResolution": "node",
        "sourceMap": true,
        "experimentalDecorators": true,
        "pretty": true,
        "noFallthroughCasesInSwitch": true,
        "noImplicitReturns": true,
        "forceConsistentCasingInFileNames": true
    },
    "files": [
        "index.ts"
    ]
}

index.ts

import { fromPairs, mapValues } from "lodash";

npm install
npx ts-node index.ts 

/Users/justin/Documents/2023/06/30/lodashrepro/node_modules/ts-node/src/index.ts:261
    return new TSError(diagnosticText, diagnosticCodes)
           ^
TSError: ⨯ Unable to compile TypeScript:
index.ts(1,21): error TS2305: Module '"../../../../../../../Users/justin/Documents/2023/06/30/lodashrepro/node_modules/@types/lodash"' has no exported member 'mapValues'.

    at createTSError (/Users/justin/Documents/2023/06/30/lodashrepro/node_modules/ts-node/src/index.ts:261:12)
    at getOutput (/Users/justin/Documents/2023/06/30/lodashrepro/node_modules/ts-node/src/index.ts:367:40)
    at Object.compile (/Users/justin/Documents/2023/06/30/lodashrepro/node_modules/ts-node/src/index.ts:558:11)
    at Module.m._compile (/Users/justin/Documents/2023/06/30/lodashrepro/node_modules/ts-node/src/index.ts:439:43)
    at Module._extensions..js (node:internal/modules/cjs/loader:1259:10)
    at Object.require.extensions.<computed> [as .ts] (/Users/justin/Documents/2023/06/30/lodashrepro/node_modules/ts-node/src/index.ts:442:12)
    at Module.load (node:internal/modules/cjs/loader:1068:32)
    at Function.Module._load (node:internal/modules/cjs/loader:909:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:82:12)
    at Object.<anonymous> (/Users/justin/Documents/2023/06/30/lodashrepro/node_modules/ts-node/src/bin.ts:157:12)

modify package.json to pin to previous version: "@types/lodash": "4.14.191"

npm install
npx ts-node index.ts

no error

modify package.json back to: "@types/lodash": "^4.14.195"

npm install
npx ts-node index.ts

still no error

justinvp commented 1 year ago

Perhaps ts-node is doing some caching that isn't invalidated? If I use the latest typescript and ts-node, I don't get the error the first time.

SpainTrain commented 1 year ago

Just ran into this with @types/lodash@4.14.197" as well