worker.start() fails if there is no process or process.env
See original GitHub issueDescribe the bug
msw is not working with the latest version, it works if I revert back to 0.25. apparently a process.env variable is needed, and I do not have one.
Environment
msw: 0.26.2
Please also provide your browser version. latest Chrome
To Reproduce
Steps to reproduce the behavior:
worker.start()
fails with following error:
Uncaught ReferenceError: process is not defined
at graphql-deps.js:790
at browser.js:8
inspection shows the that process
is required, see this part of the code found in graphql-deps.js at line 790:
/**
* A replacement for instanceof which includes an error warning when multi-realm
* constructors are detected.
*/
// See: https://expressjs.com/en/advanced/best-practice-performance.html#set-node_env-to-production
// See: https://webpack.js.org/guides/production/
var instanceOf = process.env.NODE_ENV === 'production' ? // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')
// eslint-disable-next-line no-shadow
function instanceOf(value, constructor) {
return value instanceof constructor;
} : // eslint-disable-next-line no-shadow
function instanceOf(value, constructor) {
if (value instanceof constructor) {
return true;
}
if (value) {
var valueClass = value.constructor;
var className = constructor.name;
if (className && valueClass && valueClass.name === className) {
throw new Error("Cannot use ".concat(className, " \"").concat(value, "\" from another module or realm.\n\nEnsure that there is only one instance of \"graphql\" in the node_modules\ndirectory. If different versions of \"graphql\" are the dependencies of other\nrelied on modules, use \"resolutions\" to ensure only one version is installed.\n\nhttps://yarnpkg.com/en/docs/selective-version-resolutions\n\nDuplicate \"graphql\" modules cannot be used at the same time since different\nversions may have different capabilities and behavior. The data from one\nversion used in the function from another could produce confusing and\nspurious results."));
}
}
return false;
};
Expected behavior
I would expect the mocking to work as it did with version 0.25 using a serviceworker on a web project, I would not expect to need process.env.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Why are my custom process.env not working within dotenv?
I seem to be doing something wrong in env.js when using dotenv . To clarify I'm not even pushing to Heroku yet and...
Read more >Error "process is not defined" when accessing environment ...
In React, I suppose you mean CRA because React does nothing with env variables and Remix uses React, they do the same, any...
Read more >Basic Features: Environment Variables - Next.js
Environment variables are looked up in the following places, in order, stopping once the variable is found. process.env .env.$(NODE_ENV).local .env.local (Not ...
Read more >How To Launch Child Processes in Node.js - DigitalOcean
Step 1 — Creating a Child Process with exec(). Developers commonly create child processes to execute commands on their operating system when ......
Read more >Using Environment Variables in Node.js for App Configuration ...
Because JavaScript won't error when accessing a key that doesn't exist in process.env, you'll need to design a solution for how your application ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@kettanaito I just encountered this issue today working with @LarsDenBakker 's web-dev-server. The issue is that its expecting
process.env
which Webpack will happily fill for you, but@web/dev-server
will not fill this for you.Heres the simplest reproduction repo I could make:
https://github.com/ParamagicDev/msw-process-env-issue
Web dev server doesnt actually run any build at all, it picks up the es module distribution and serves it to the browser as is. Since process is a node js global, it wont work in the browser.