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

Cannot find module 'rollup/parseAst' or its corresponding type declarations. #5199

Closed
sagargurtu opened this issue Oct 13, 2023 · 12 comments
Closed

Comments

@sagargurtu
Copy link

Rollup Version

v4.0.2

Operating System (or Browser)

Chrome

Node Version (if applicable)

No response

Link To Reproduction

https://stackblitz.com/edit/parseast-error?file=src%2Fmain.ts,tsconfig.json

Expected Behaviour

Importing from 'rollup/parseAst' should not throw error.

Actual Behaviour

Importing from 'rollup/parseAst' throws the following error:

Cannot find module 'rollup/parseAst' or its corresponding type declarations.
@lukastaegert
Copy link
Member

Unfortunately, this only works if you set "moduleResolution": "node16" (or "bundler") in your tsconfig.json.

@sagargurtu
Copy link
Author

sagargurtu commented Oct 14, 2023

"node16" has its own set of issues. Reproduction: https://stackblitz.com/edit/parseast-error-gfgsbm?file=src%2Fmain.ts

See microsoft/TypeScript#50058

Do you have a workaround?

@TrickyPi
Copy link
Member

One workaround, Setting "moduleResolution": "Bundler" in your tsconfig.json.

@skhaz
Copy link

skhaz commented Mar 22, 2024

I am still experiencing this issue. Why has it been closed?

Yang-33 added a commit to line/line-bot-sdk-nodejs that referenced this issue Apr 2, 2024
When line-bot-sdk-nodejs supports ESM, we will use ESM code for testing.
Vitest supports ESM+Typescript. This change will switch from using mocha
to using vitest.

Also, along with mocha, nyc will be removed from dependencies because
vitest supports coverage as well.

About the workaround:
1. Running vitest 1.4.0 results in TypeScript errors due to an issue
with vite, which vitest uses. The latest version of vite has fixed this,
so I explicitly added the latest vite to the dev dependencies.
    - vitejs/vite#15714
2. Running vite for CJS leads to TypeScript errors due to an issue with
rollup, which vite uses. There is no good workaround for CJS. I resolved
this by rewriting node_modules as a workaround. There are no problems
using vitest(?)
   * rollup/rollup#5199
   * vitest-dev/vitest#4567
@okinawaa
Copy link

okinawaa commented Apr 4, 2024

me too still experiencing this issue.

@AmorZhao
Copy link

Also still experiencing this issue.

@lukastaegert
Copy link
Member

lukastaegert commented Apr 16, 2024

I am still experiencing this issue. Why has it been closed?

Because everything is working as intended and setting moduleResolution: "bundler" or "node16" fixes it. If you cannot do that for some reason, you can instead try to import from "rollup/dist/parseAst" or "rollup/dist/parseAst.js", which is the actual file location.

@dirkluijk
Copy link

Note that this is breaking for anyone having a TS project with ES modules using rollup as transitive dependency. For example, I am using vitest, which depends on vite, which has an import for rollup/parseAst that breaks for me.

My workaround now is to add a custom mapping in my tsconfig.json:

"paths": {
  // workaround for: https://github.com/vitest-dev/vitest/issues/4567
  "rollup/parseAst": ["./node_modules/rollup/dist/parseAst"]
}

I am not an export in module systems in the JavaScript ecosystem. Should I report this with Vitest?

@dirkluijk
Copy link

Never mind, adding "skipLibCheck": true resolved the issue for me and doesn't require any hacky workaround.

@skhaz
Copy link

skhaz commented May 6, 2024

skipLibCheck is a hack IMO.

@jordi-studyportals
Copy link

jordi-studyportals commented May 8, 2024

I ran into this issue while using vitest. I got the rollup error because vitest was using vite, so I couldn't change the import.
node_modules/vite/dist/node/index.d.ts:5:41 - error TS2307: Cannot find module 'rollup/parseAst' or its corresponding type declarations.

My problem was caused by tsc because my test folder and vitest.config.ts file were included into the typescript build of my project by accident. I had to add the folder and the vitest.config.ts file to the exluded items in my tsconfig and that resolved the issues for me.

@dirkluijk
Copy link

As suggested by @jordi-studyportals, I removed skipLibCheck: true and added "vitest.config.ts" and "**/**.test.ts" to my tsconfig exclude list instead. That did the trick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants