Skip to content

ERR_REQUIRE_ESM building with ViteJS and vite-ssg #1625

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

Closed
mq1 opened this issue Apr 26, 2021 · 6 comments
Closed

ERR_REQUIRE_ESM building with ViteJS and vite-ssg #1625

mq1 opened this issue Apr 26, 2021 · 6 comments

Comments

@mq1
Copy link

mq1 commented Apr 26, 2021

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: C:\Users\Manuel Quarneti\Desktop\runmc\node_modules\.pnpm\@tauri-apps+api@1.0.0-beta-rc.3\node_modules\@tauri-apps\api\tauri-3328260d.js
require() of ES modules is not supported.
require() of C:\Users\Manuel Quarneti\Desktop\runmc\node_modules\.pnpm\@tauri-apps+api@1.0.0-beta-rc.3\node_modules\@tauri-apps\api\tauri-3328260d.js from C:\Users\Manuel Quarneti\Desktop\runmc\node_modules\.pnpm\@tauri-apps+api@1.0.0-beta-rc.3\node_modules\@tauri-apps\api\tauri.cjs is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename tauri-3328260d.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from C:\Users\Manuel Quarneti\Desktop\runmc\node_modules\.pnpm\@tauri-apps+api@1.0.0-beta-rc.3\node_modules\@tauri-apps\api\package.json.

    at new NodeError (node:internal/errors:329:5)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1109:13)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Module.require (node:internal/modules/cjs/loader:996:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at Object.<anonymous> (C:\Users\Manuel Quarneti\Desktop\runmc\node_modules\.pnpm\@tauri-apps+api@1.0.0-beta-rc.3\node_modules\@tauri-apps\api\tauri.cjs:1:75)
    at Module._compile (node:internal/modules/cjs/loader:1092:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
    at Module.load (node:internal/modules/cjs/loader:972:32) {
  code: 'ERR_REQUIRE_ESM'
}
@mq1 mq1 added the type: bug label Apr 26, 2021
@nothingismagick
Copy link
Member

can you please share exactly how you are importing? have you tried importing the ts directly? or are you using require...

@mq1
Copy link
Author

mq1 commented Apr 26, 2021

My only import from tauri api is import { invoke } from '@tauri-apps/api/tauri' from ts.
How do I import the ts directly?

@nothingismagick
Copy link
Member

Try this

import { invoke } from '@tauri-apps/api/tauri.ts'

@mq1
Copy link
Author

mq1 commented Apr 26, 2021

Try this

import { invoke } from '@tauri-apps/api/tauri.ts'

[vite:resolve] Missing "./tauri.ts" export in "@tauri-apps/api" package

@lucasfernog
Copy link
Member

I think vite only follows package.json > exports field :( I see that your vite is trying to load the .cjs files though:

at Object.<anonymous> (C:\Users\Manuel Quarneti\Desktop\runmc\node_modules\.pnpm\@tauri-apps+api@1.0.0-beta-rc.3\node_modules\@tauri-apps\api\tauri.cjs:1:75)

Maybe something isn't configured properly?

@mq1
Copy link
Author

mq1 commented Apr 26, 2021

Thank you!

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

3 participants