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

Error require is not defined #2161

Closed
Justinidlerz opened this issue Feb 22, 2021 · 2 comments
Closed

Error require is not defined #2161

Justinidlerz opened this issue Feb 22, 2021 · 2 comments

Comments

@Justinidlerz
Copy link
Contributor

Justinidlerz commented Feb 22, 2021

Describe the bug

Throw an error require is not defined when using viteDevServer.ssrLoadModule to load the SSR entry file.
Seems the error come from the pkg apollo-upload-client import the extract-files
image
But the errors to require file is existing

And the error does not throw when I using vite build --ssr index.ts

Reproduction

  1. Create a file then import the apollo-upload-client', see like:
import 'apollo-upload-client';
  1. Create the build file, see like:
const path = require('path');
const {createServer} = require('vite');

const build = async () => {
	const devServer = await createServer({});

	const entryPath = path.resolve(__dirname, './index.ts');
	const App = await devServer.ssrLoadModule(entryPath);

	console.log(App);
};

build()
	.then(() => {
		console.log(`Build pages done.`);
		process.exit(0);
	})
	.catch((e) => {
		console.error(`Build pages failed.`);
		console.error(e);
		process.exit(1);
	});
  1. Run the script
node build.js

Then get the error.

System Info

  • vite version: 2.0.1
  • Operating System: macOS 10.15.7 (19H2) Darwin 19.6.0
  • Node version: v12.18.3
  • Package manager (npm/yarn/pnpm) and version: yarn: 1.22.10
@Justinidlerz
Copy link
Contributor Author

Justinidlerz commented Feb 23, 2021

Vite upgrade to version: 2.0.2

The error still exists
image

This is the error thrown content:
image

@Justinidlerz
Copy link
Contributor Author

Remove the apollo-upload-client, the same error throw in other pkg

image

@Justinidlerz Justinidlerz changed the title Throw an error require is not defined when using viteDevServer.ssrLoadModule Error require is not defined Feb 24, 2021
@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