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

A dependency having an export map without a "." field will cause SSR imports to throw #1854

Closed
ggoodman opened this issue Feb 3, 2021 · 0 comments

Comments

@ggoodman
Copy link

ggoodman commented Feb 3, 2021

Describe the bug

Given an npm module that has an export map defining deep imports but NOT defining a root import such as the one for nostalgie, the heuristics for determining if the module should be treated as 'external' or not will throw due to the call here:

const entry = tryNodeResolve(id, undefined, root, false)?.id
.

The resulting stack trace will be something like:

Error: Missing "." export in "nostalgie" package
    at bail (/Users/ggoodman/Projects/ggoodman/nostalgie/node_modules/vite/dist/node/chunks/dep-0b3f4801.js:40013:8)
    at resolve$1 (/Users/ggoodman/Projects/ggoodman/nostalgie/node_modules/vite/dist/node/chunks/dep-0b3f4801.js:40089:10)
    at resolveExports (/Users/ggoodman/Projects/ggoodman/nostalgie/node_modules/vite/dist/node/chunks/dep-0b3f4801.js:40099:12)
    at resolvePackageEntry (/Users/ggoodman/Projects/ggoodman/nostalgie/node_modules/vite/dist/node/chunks/dep-0b3f4801.js:40389:22)
    at tryNodeResolve (/Users/ggoodman/Projects/ggoodman/nostalgie/node_modules/vite/dist/node/chunks/dep-0b3f4801.js:40289:11)
    at resolveSSRExternal (/Users/ggoodman/Projects/ggoodman/nostalgie/node_modules/vite/dist/node/chunks/dep-0b3f4801.js:40553:29)

Reproduction

This can be reproduced with the following:

npm install --save nostalgie

src/App.tsx:

import { useAuth } from 'nostalgie/auth';

export default function App() {
  const appState = useAuth();
}

bundler.ts:

import pluginReactRefresh from '@vitejs/plugin-react-refresh';
import * as Path from 'path';
import { createLogger, createServer, Logger, ViteDevServer } from 'vite';
import type { RuntimeConfiguration } from './types';

const logger = createLogger();

async function main(logger: Logger, config: RuntimeConfiguration) {
  const vite = await createServer({
    plugins: [pluginReactRefresh()],
  });

  const foo = await importReactApp(logger, config, vite);

  console.dir(foo);
}

function importReactApp(logger: Logger, config: RuntimeConfiguration, vite: ViteDevServer) {
  return (vite as any).ssrLoadModule(config.reactAppEntryPath) as Promise<() => JSX.Element>;
}

const rootDir = Path.resolve(__dirname, '.'); // Modified for this repro

main(logger, {
  nodeEnv: 'development',
  reactAppEntryPath: Path.resolve(rootDir, './src/App.tsx'),
  rootPath: rootDir,
}).catch((err) => {
  logger.error(err);
  process.exit(1);
});

System Info

  • vite version: 2.0.0-beta.62
  • Operating System: MacOS 11.2
  • Node version: v14.15.4
  • Package manager (npm/yarn/pnpm) and version: 6.14.10

Logs (Optional if provided reproduction)

  1. Run vite or vite build with the --debug flag. N/A
  2. Provide the error log here. See above
@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant