teambit / bit.envs

DEPRECATED - Bit compilers and testers were moved to https://github.com/teambit/envs
https://bit.dev/bit/envs
Other
23 stars 9 forks source link

[React-TypeScript] the main of the package points to ts file #43

Closed danielkcz closed 4 years ago

danielkcz commented 4 years ago

Just used the Bit for a first time to export a couple of React Hooks we have. Hooks are not exactly components, but I don't see why it shouldn't work :) Problem is that generated package.json has main field pointing to the source .ts file instead of the one from dist.

https://bit.dev/speedlo/hooks/use-async-effect/~code

To properly consume such hook we would have to do the following and that's fairly ugly :)

import { useAsyncEffect } from "@bit/speedlo.hooks.use-async-effect/dist/use-async-effect/useAsyncEffect";

Is it some configuration I am missing or why is that happening?

danielkcz commented 4 years ago

I am trying to understand where and how is the package.json generated. When building locally, it actually finds the correct main in dist folder. However, the .bitmap files have it like that...

    "speedlo.hooks/use-async-effect@0.0.1": {
        "files": [
            {
                "relativePath": "src/useAsyncEffect.ts",
                "test": false,
                "name": "useAsyncEffect.ts"
            }
        ],
        "mainFile": "src/useAsyncEffect.ts",
        "origin": "AUTHORED",
        "exported": true
    },

No mention of the dist file. I tried ...

bit add -i use-async-effect -m dist/use-async-effect/useAsyncEffect.js
error: file or directory "" was not found.

run 'bit doctor' to get detailed workspace diagnosis and issue resolution.

It's really strange how is this supposed to work.

JoshK2 commented 4 years ago

Which version of the compiler you use?

danielkcz commented 4 years ago

Well, yesterday it was react-typescript@3.0.13. Today I noticed there was a 3.0.14, but I wasn't able to get it to build. It's really strange considering the tsconfig hasn't changed and I am not even using those types anywhere in the code.

Command failed: D:\repo\node_modules\typescript\bin\tsc -d

error TS2318: Cannot find global type 'Array'.
error TS2318: Cannot find global type 'Boolean'.
error TS2318: Cannot find global type 'Function'.
error TS2318: Cannot find global type 'IArguments'.
error TS2318: Cannot find global type 'Number'.
error TS2318: Cannot find global type 'Object'.
error TS2318: Cannot find global type 'RegExp'.
error TS2318: Cannot find global type 'String'.

Error: Command failed: D:\repo\node_modules\typescript\bin\tsc -d

error TS2318: Cannot find global type 'Array'.
error TS2318: Cannot find global type 'Boolean'.
error TS2318: Cannot find global type 'Function'.
error TS2318: Cannot find global type 'IArguments'.
error TS2318: Cannot find global type 'Number'.
error TS2318: Cannot find global type 'Object'.
error TS2318: Cannot find global type 'RegExp'.
error TS2318: Cannot find global type 'String'.

    at makeError (D:\repo\packages\hooks\.bit\components\compilers\react-typescript\bit.envs\3.0.14\components\.dependencies\compilers\typescript\bit.envs\3.0.6\node_modules\execa\index.js:174:9)

I wonder, why does 3.0.14 depends on 3.0.6 of typescript compiler while 3.0.13 depends on 3.0.12?

qballer commented 4 years ago

Hi, I've published a new version of the compiler yesterday. This is causing most of the issues. I will look at this now.

qballer commented 4 years ago

@FredyC can you try the latest compiler version ?

danielkcz commented 4 years ago

@qballer Well, it builds now, but still the same issue with main, pointing to source "ts" file.

https://bit.dev/fredyc/test/use-mount-log

my collection for testing

qballer commented 4 years ago

I think that this conversation is best continued in gitter: https://gitter.im/bit-src/Bit Would you mind coming online?

danielkcz commented 4 years ago

@qballer Thanks again. It's fixed with 3.0.16.