`ReferenceError: window is not defined` in 0.32.0
See original GitHub issueWhat happens and why it is wrong
Environment
- Yarn 3
Versions
The command to use envinfo
throws an error, so I’m resorting to copy-paste. All versions are latest.
"rollup": "^2.75.5",
"rollup-plugin-typescript2": "^0.32.0",
"typescript": "^4.7.2"
The error resides here:
if (typeof commonjsRequire === "function") {
try {
lodash = {
clone: require("lodash/clone"),
constant: require("lodash/constant"),
each: require("lodash/each"),
filter: require("lodash/filter"),
has: require("lodash/has"),
isArray: require("lodash/isArray"),
isEmpty: require("lodash/isEmpty"),
isFunction: require("lodash/isFunction"),
isUndefined: require("lodash/isUndefined"),
keys: require("lodash/keys"),
map: require("lodash/map"),
reduce: require("lodash/reduce"),
size: require("lodash/size"),
transform: require("lodash/transform"),
union: require("lodash/union"),
values: require("lodash/values")
};
} catch (e) {
// continue regardless of error
}
}
if (!lodash) {
lodash = window._;
}
The line saying to use window._
throws an error because window
does not exist in the Node environment.
This is newly introduced in 0.32.0. Reverting to 0.31.0 fixes this.
Issue Analytics
- State:
- Created a year ago
- Comments:16
Top Results From Across the Web
ReferenceError: window is not defined in JavaScript
The "ReferenceError: window is not defined" error occurs for multiple reasons: ... The window represents a window containing a DOM document and is...
Read more >referenceerror: window is not defined, how to solve
Here's how to fix the “referenceerror: window is not defined” error that you might have in Node.js or with a tool like Next.js....
Read more >ReferenceError : window is not defined at object. <anonymous ...
In my web I have 3 JavaScript files : client.js , server.js , myModule.js . In client.js I create a window variable called...
Read more >How to solve "window is not defined" errors in React and Next.js
Because in the Node.js world, window is not defined, window is only available in browsers. There are three ways to solve that: 1....
Read more >How To Solve ReferenceError window is not defined in ...
If you are specifically working on a Node.js application and still receive this error, it is because the window object does not actually...
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
A bugfix has been released in
0.32.1
🎉I’ve also confirmed that
0.32.1
works inside of rpt2, in one of my own libraries, and the library that I was able to repro the bug in above,gismeteo
.Thanks to everyone for submitting this issue, providing repros, etc not too long after
0.32.0
’s release so it could get addressed quickly!Annnd yep, this exact piece of code that requires
lodash
changes in that exact commit: https://github.com/ezolenko/rollup-plugin-typescript2/commit/08d2f5bcad7cb9a9a0974f3707a27d29dd89da7c#diff-80441564774ccf83c60a1616524830d5c15a9bc194b62e2c3d9f43de805c62d0L22435Updating to
@rollup/plugin-commonjs
to v22.0.0 once again changes that piece of code and seems to fix the issue when I test with either Yarn or NPM ingismeteo
Can install via my
issue-339
branch to workaround this issue for now. Will make a PR shortly, but have to wait on @ezolenko for a release.In the meantime, @CharlesStover can you confirm that installing my
issue-339
branch fixes this for you as well?