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

Compilation issue in mixed js/ts projects for const enums #246

Open
Sv-Th opened this issue Aug 2, 2023 · 2 comments
Open

Compilation issue in mixed js/ts projects for const enums #246

Sv-Th opened this issue Aug 2, 2023 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@Sv-Th
Copy link

Sv-Th commented Aug 2, 2023

We have a project that was initially built in pure JavaScript. With the release of the typescript support, we ported the business logic of our project to typescript.
Most, if not all, of the UI logic is still in JavaScript.

Since the latest release of the lighting-CLI (2.12.0) this project gives us issues when compiling. Below the output of the attached minimal example project.

[!] Error: 'brokenEnum' is not exported by src/enum.ts, imported by src/App.js
https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module
src/App.js (2:9)
1: import { Lightning, Utils } from "@lightningjs/sdk";
2: import { brokenEnum } from "./enum";
            ^
3: 
4: export default class App extends Lightning.Component {

The error seems specifically related to importing const enums in .js files from .ts files. When we remove const the project compiles.
When we build the same project with the previous version of lightning-cli (2.11.0) there also is no issue.

com.domain.app.brokenEnum.zip

While asking on the community discord we found following additional result:
I noticed this line in the commit.
fs.existsSync(path.join(process.cwd(), 'tsconfig.json')) && typescript(),

I deleted our tsconfig.json file and now it seems to compile correctly. So it gives the error mentioned when using the default tsconfig that is generated when using lng create.
But it compiles fine when we have no tsconfig and it falls back to (if i understand correctly) the default rollup config

Is it recommended to have no tsconfig.json?
Seems strange that lng create would add one in that case.

@sandeep-vedam sandeep-vedam self-assigned this Aug 4, 2023
@sandeep-vedam sandeep-vedam added the bug Something isn't working label Aug 18, 2023
@frank-weindel
Copy link
Contributor

@Sv-Th What does your project's tsconfig.json look like? TypeScript has a compiler option called isolatedModules. When enabled you are not allowed to use const enum references in your project. It is not enabled by default which might explain why your project compiles without the tsconfig.json present.

@Sv-Th
Copy link
Author

Sv-Th commented Aug 31, 2023

Hi,

This was our tsconfig.json:

{
  "compilerOptions": {
    "outDir": "build-ts",
    "target": "ES2018",
    "lib": ["ES2015", "DOM"],
    "moduleResolution": "node",
    "strict": true,
    "noUncheckedIndexedAccess": true,
    "noImplicitOverride": true,
    "allowJs": true,
    "resolveJsonModule": true
  }
}

We also observed the issue with the default config generated by lightning cli.

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

No branches or pull requests

3 participants