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

typescript compile error TS1479 #207

Closed
retorquere opened this issue Jan 13, 2023 · 10 comments · Fixed by #213
Closed

typescript compile error TS1479 #207

retorquere opened this issue Jan 13, 2023 · 10 comments · Fixed by #213

Comments

@retorquere
Copy link

retorquere commented Jan 13, 2023

Describe the bug
When I try to import eta in my project with

import * as Eta from 'eta'

I get

error TS1479: 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("eta")' call instead.
  To convert this file to an ECMAScript module, change its file extension to '.mts', or add the field `"type": "module"` to 'package.json'.

To Reproduce

tsconfig.json:

{
  "compilerOptions": {
    "allowUnreachableCode": false,
    "noUnusedLocals": true,
    "isolatedModules": true,
    "esModuleInterop": true,
    "noUnusedParameters": false,
    "importHelpers": true,
    "target": "es2017",
    "disableSizeLimit": true,
    "module": "commonjs",
    "noImplicitAny": false,
    "removeComments": false,
    "preserveConstEnums": true,
    "sourceMap": false,
    "downlevelIteration": true,
    "resolveJsonModule": true,
    "moduleResolution": "node16",
    "skipLibCheck": true,
    "lib": [ "es2017", "dom", "dom.iterable", "webworker" ]
  },
  "include": [ "index.ts" ],
  "exclude": [ "node_modules" ]
}

index.ts:

import * as Eta from 'eta'
console.log(Eta)

package.json:

{
  "name": "tt",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "tsc --noemit"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "eta": "^1.13.0",
    "tslib": "^2.4.1",
    "typescript": "^4.9.4"
  }
}

type: npx tsc --noemit

Expected behavior

No error :)

Package & Environment Details

  • Environment: Node
  • Version: 18.9.0
@nebrelbug
Copy link
Collaborator

@retorquere interesting. Does this issue happen with [email protected]?

@retorquere
Copy link
Author

Yes.

@retorquere
Copy link
Author

It's the moduleResolution. If I set it to node instead of node16, the error goes away. But I've had it set to node16 for ages.

@nebrelbug
Copy link
Collaborator

@retorquere ok, I think the issue is that eta doesn't have a separate types file for eta.es.js and eta.cjs. I'm going to be updating Eta's build process, so I will try to fix this sometime (hopefully) in the next few days.

@nebrelbug
Copy link
Collaborator

@retorquere just published a new release which aims to improve NodeNext support. Will you check to see if it resolved the issue?

@DanSnow
Copy link

DanSnow commented Jan 22, 2023

We still got an error when upgrading to 1.14.1 storipress/unplugin-eta#126

@retorquere
Copy link
Author

For me the error is now gone, thanks!

@gurgunday
Copy link
Contributor

We still got an error when upgrading to 1.14.1 storipress/unplugin-eta#126

Yeah, I can reproduce. PR is up.

nebrelbug pushed a commit that referenced this issue Jan 23, 2023
Co-authored-by: Gün <Gün>
Closes #207
@nebrelbug
Copy link
Collaborator

@retorquere I'm glad that worked!

@DanSnow I just merged @gurgunday's commit and published a new patch version, which should solve the problem.

@DanSnow
Copy link

DanSnow commented Jan 24, 2023

@nebrelbug It's fixed. Thanks 🎉

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

Successfully merging a pull request may close this issue.

4 participants