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

Importing from vike/server throws error, missing /dist/esm/node/runtime/index.mjs #2040

Closed
flipswitchingmonkey opened this issue Dec 30, 2024 · 9 comments
Labels

Comments

@flipswitchingmonkey
Copy link

Description

I'm importing vike's renderPage and bundle it through rollup. This works fine if I import like so:

import { renderPage } from 'vike'

However this is deprecated and outputs the notification that imports should be done from

import { renderPage } from 'vike/server'

This, however, ends up with this error:

✖ Failed
[RollupError] Could not resolve "./dist/esm/node/runtime/index.mjs" from "node_modules/.pnpm/[email protected][email protected]_@[email protected][email protected]_/node_modules/vike/server.js"

/Users/michael/dev/experiments/vike/node_modules/.pnpm/[email protected][email protected]_@[email protected][email protected]_/node_modules/vike/server.js
RollupError: Could not resolve "./dist/esm/node/runtime/index.mjs" from "node_modules/.pnpm/[email protected][email protected]_@[email protected][email protected]_/node_modules/vike/server.js"
    at error (file:///Users/michael/dev/experiments/vike/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:2287:30)
    at ModuleLoader.handleInvalidResolvedId (file:///Users/michael/dev/experiments/vike/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:24860:24)
    at file:///Users/michael/dev/experiments/vike/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:24822:26

I wonder whether rollup may be part of the problem here, but looking at the actually imported package from node_modules/vike/server.js, it tries to import ./dist/esm/node/runtime/index.mjs which does not exist

@brillout
Copy link
Member

If you remove the file node_modules/vike/server.js does it work then?

@flipswitchingmonkey
Copy link
Author

No, as expected it is then treated as an 'external dependency' sind the import is simply missing. If however I edit server.js to export from index.js instead of index.mjs, then it works.

@brillout
Copy link
Member

brillout commented Jan 2, 2025

It's defined over package.json#exports, so it should be working. I'm actually considering doing this: 5c0ce1d. Can you publish a reproduction?

@brillout
Copy link
Member

brillout commented Jan 5, 2025

I went ahead with the aforementioned patch (pre-released as 0.4.212-commit-1c62ff2), but let me know if it doesn't work for you; I'm happy to revive those resolve fallbacks if I'm given a minimal reproduction.

@flipswitchingmonkey
Copy link
Author

As before it works if I import from vike directly but now, since it is now removed, importing from vike/server will not work. Importing from vike still outputs the error, so presusambly this warning needs to be removed as well?

2025-01-06 08:29:41 Error: [vike][Warning] You have following imports which are outdated:
2025-01-06 08:29:41   import { something } from 'vike'
2025-01-06 08:29:41 Replace them with:
2025-01-06 08:29:41   import { something } from 'vike/server'
2025-01-06 08:29:41 Or if something is a type:
2025-01-06 08:29:41   import type { something } from 'vike/types'
2025-01-06 08:29:41 Make sure to import renderPage(), escapeInject, html, dangerouslySkipEscape(), pipeWebStream(), pipeNodeStream(), pipeStream(), stampPipe() from 'vike/server'. (Or inspect the error stack below to find the import causing this warning.)

@brillout
Copy link
Member

brillout commented Jan 6, 2025

importing from vike/server will not work.

I'll need a minimal reproduction here. (So that I can take the decision whether it's an issue with your build setup or whether Vike should revive those resolve fallbacks.)

@flipswitchingmonkey
Copy link
Author

Here you go: https://github.com/flipswitchingmonkey/issue_vike_import

It's being imported in src/frontend/index.ts (ignore the sirv import, it makes no difference)

@brillout
Copy link
Member

brillout commented Jan 7, 2025

It does seem to be an issue about your build setup (I guess Directus's side). But I'll revive the resolve fallbacks nevertheless.

@brillout brillout reopened this Jan 7, 2025
brillout added a commit that referenced this issue Jan 7, 2025
@brillout
Copy link
Member

brillout commented Jan 7, 2025

Pre-released as 0.4.212-commit-962127b.

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

No branches or pull requests

2 participants