admin管理员组文章数量:1404923
I'm installing the service following the steps at the official docs:
This piece of code:
if (process.env.NODE_ENV === 'development') {
const { worker } = require('../tests/mocks/browser');
worker.start();
}
Uncaught ReferenceError: require is not defined
I've setup the project using Vite. What's the correct approach to solving this.
I'm installing the service following the steps at the official docs: https://mswjs.io/docs/getting-started/install
This piece of code:
if (process.env.NODE_ENV === 'development') {
const { worker } = require('../tests/mocks/browser');
worker.start();
}
Uncaught ReferenceError: require is not defined
I've setup the project using Vite. What's the correct approach to solving this.
Share Improve this question asked Feb 26, 2023 at 22:02 Daniel TkachDaniel Tkach 7462 gold badges14 silver badges23 bronze badges1 Answer
Reset to default 8Vite does not use require, try to use import instead:
if (process.env.NODE_ENV === 'development') {
const { worker } = await import('../tests/mocks/browser');
worker.start();
}
Source (albeit another issue, but works here as well): https://github./vitejs/vite/issues/3409#issuement-841049875
本文标签: javascriptMSW (Mock Service Worker)Vite Uncaught ReferenceError require is not definedStack Overflow
版权声明:本文标题:javascript - MSW (Mock Service Worker) + Vite: Uncaught ReferenceError: require is not defined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744876860a2629966.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论