-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
ReferenceError: _objectSpread is not defined after update #10179
Comments
Hey @jenniferlynparsons! We really appreciate you taking the time to report an issue. The collaborators If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack |
Can you post your webpack config? {
"env": {
"test": {
"plugins": [
"@babel/plugin-proposal-dynamic-import",
"@babel/plugin-transform-runtime"
]
},
"production": {
"plugins": ["babel-plugin-jsx-remove-data-test-id"]
}
},
"presets": ["@babel/preset-env", "@babel/preset-react"],
"plugins": ["@babe/plugin-transform-class-properties"]
}
|
I installed the plugins from scratch without indicating version number, so I'll have to see if there are updated versions available somewhere or if 7 allows me to drop them entirely. Here's my webpack config:
|
A bit more investigation leads to Jest being part of the problem. That's where I'm getting that error, specifically. It requires things like |
Further update: Earlier today I had rolled back to my previous branch and everything worked correctly. The only difference between the two branches is that I installed Yup (https://github.com/jquense/yup) for some error validation. |
Installing a new package might have changed other things in your lockfile. Recent versions of Jest use Babel 7, which version are you using? |
I'm on the most current version of Jest. The project I'm working on is fairly new (started in October/November) and I had just updated everything last week, so it's all current versions, or as close as possible. The only difference, package-wise, between my previous branch and the current one where things are broken, is that I installed Yup. |
I am getting this same issue ... downgrading fixed the issue (my previous version was 7.4.4). My issue does not deal with Jest, it prevents my app from rendering locally. |
Can someone of you share a small repository which reproduces the issue? |
I would have to make one, currently it is happening on internal private repositories. |
Hopefully you would only need the same config and a one-line sample file to transpile. |
@nicolo-ribaudo here's my current branch where it's failing https://github.com/jenniferlynparsons/cuppa-webpack/tree/feature/login-form-validation I've got it narrowed down at the moment to the AuthReducer.js file where I've added the "LOGIN_ERRORS" case. The case before that ("USER_LOADING") is the one that's failing in the AuthReducers.test.js file. Sorry I can't get it narrowed down any further than that. I've also noticed that if I remove the "LOGIN_ERRORS" case, the tests pass. There's no reason that I can see why that would have any effect unless there's some edge case I'm hitting that I'm unaware of. |
I tried downloading that branch, updating Babel plugins to v7 and
|
Well, that's encouraging! @nicolo-ribaudo can you clarify which plugins should be updated? And is it enough to run I ask because when i run |
Oh yeah, sorry for not being clear. We renamed the packages in Babel 7: package.json "devDependencies": {
"@babel/cli": "^7.4.3",
"@babel/core": "^7.4.3",
"@babel/plugin-proposal-class-properties": "^7.4.4",
"@babel/plugin-transform-runtime": "^7.4.4",
"@babel/preset-env": "^7.5.2",
"@babel/preset-react": "^7.0.0",
"@testing-library/react": "^8.0.1",
"babel-eslint": "^10.0.1",
"babel-jest": "^24.7.1",
"babel-loader": "^8.0.5",
"babel-plugin-jsx-remove-data-test-id": "^2.0.0",
"eslint": "^5.16.0",
"eslint-config-prettier": "^4.1.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-prettier": "^3.0.1",
"eslint-plugin-react": "^7.12.4",
"html-webpack-plugin": "^3.2.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^24.8.0",
"jest-dom": "^3.5.0",
"jsdoc": "^3.6.2",
"lodash": "^4.17.11",
"moxios": "^0.4.0",
"nodemon": "^1.18.11",
"prettier": "^1.16.4",
"react-svg-loader": "^2.1.0",
"react-test-renderer": "^16.8.6",
"redux-devtools-extension": "^2.13.8",
"redux-mock-store": "^1.5.3",
"sass": "^1.18.0",
"webpack": "^4.29.6",
"webpack-cli": "^3.3.0",
"webpack-dev-server": "^3.3.1"
}, .babelrc {
"env": {
"test": {
"plugins": ["@babel/transform-runtime"]
},
"production": {
"plugins": ["babel-plugin-jsx-remove-data-test-id"]
}
},
"presets": ["@babel/env", "@babel/react"],
"plugins": ["@babel/proposal-class-properties"]
} |
@jenniferlynparsons where is @babel/plugin-proposal-object-rest-spread in your .babelrc? |
Thanks for the clarification @nicolo-ribaudo ! Looks like I'm still having issues, but I can move forward with more confidence that it's not a babel issue. Time to try restarting the machine. :D |
@mstruensee I didn't have it in mine. Just tried adding it and wow that made everything so much worse. lol. Now I'm not just getting the error on the one test, but on most of them. |
Okay, I think (fingers crossed) I have it fixed. For me, it took uninstalling |
I suggest never I stalling packages globally, always use the local copy. |
I had the same problem. I use this with In: export const handlePages = (pages, removeIcon = false) =>
(pages || []).map(
({ pages: subPages, newWindow, params, icon, ...page }) => ({
...page,
newWindow: !!newWindow,
params: params || {},
pages: handlePages(subPages),
icon:
removeIcon && !icon?.use
? null
: {
direction: icon?.direction || 'right',
font: icon?.font || null,
image: icon?.image || null,
},
}),
);
export default ({ design, pages, ...menu }) => ({
...menu,
pages: handlePages(pages),
design: {
...design,
showLogo: design?.showLogo || false,
...
}); Out: var handlePages = function handlePages(pages) {
var removeIcon = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
return (pages || []).map(function (_ref) {
var subPages = _ref.pages,
newWindow = _ref.newWindow,
params = _ref.params,
icon = _ref.icon,
page = _babel_runtime_helpers_objectWithoutProperties__WEBPACK_IMPORTED_MODULE_1___default()(_ref, ["pages", "newWindow", "params", "icon"]);
return _babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0___default()({}, page, {
newWindow: !!newWindow,
params: params || {},
pages: handlePages(subPages),
icon: removeIcon && !(icon === null || icon === void 0 ? void 0 : icon.use) ? null : {
direction: (icon === null || icon === void 0 ? void 0 : icon.direction) || 'right',
font: (icon === null || icon === void 0 ? void 0 : icon.font) || null,
image: (icon === null || icon === void 0 ? void 0 : icon.image) || null
}
});
});
};
/* harmony default export */ __webpack_exports__["a"] = (function (_ref2) {
var design = _ref2.design,
pages = _ref2.pages,
menu = _babel_runtime_helpers_objectWithoutProperties__WEBPACK_IMPORTED_MODULE_1___default()(_ref2, ["design", "pages"]);
return _objectSpread({}, menu, {
pages: handlePages(pages),
design: _objectSpread({}, design, {
... Some
module.exports = {
presets: [
[
'@babel/env',
{
useBuiltIns: 'usage',
corejs: '2.6.9',
},
],
'@babel/react',
'@babel/preset-typescript',
],
plugins: [
'@babel/transform-runtime',
'@babel/proposal-optional-chaining',
'@babel/proposal-export-default-from',
[
'@babel/proposal-decorators',
{
legacy: true, // TODO: remove, typescript not support
},
],
'@babel/proposal-class-properties',
[
'transform-imports',
{
/* eslint-disable no-template-curly-in-string */
antd: {
transform: 'antd/lib/${member}',
kebabCase: true,
},
lodash: {
transform: 'lodash/${member}',
},
fbjs: {
transform: 'fbjs/lib/${member}',
},
validator: {
transform: 'validator/lib/${member}',
},
'react-icons/fa': {
transform: 'react-icons/lib/fa/${member}',
kebabCase: true,
},
'react-icons/md': {
transform: 'react-icons/lib/md/${member}',
kebabCase: true,
},
/* eslint-enable no-template-curly-in-string */
},
],
'idx',
[
'module-resolver',
{
root: ['./src'],
cwd: 'packagejson',
},
],
'css-modules-transform',
],
}; @nicolo-ribaudo do you have any idea? |
This seems like a problem with webpack, which only transpiles some usages of the imported helper and not all of them. |
After I tested, this work correctly when I downgrade to |
i have similar problem, but my config has only 2 plugins
babel generate function _objectSpread2 but tries to use _objectSpread2 and _objectSpread, and it causes error "_objectSpread is not defined" |
@v-angolenko @HsuTing Can you provide a repository which shows the issue? |
I was having this issue when running tests in Jest, after upgrading babel + plugins. I found that running
|
I've tried everything in this list in our yarn workspaces monorepo. I've added the
I've run With every attempt to fix this issue I've run
Anyone manage to work around this without one of the already-mentioned solutions? UPDATE (SOLVED): Worked with a fresh checkout. Must have missed a |
Babel seems to need a specific package to support the `...` operator for now. See: babel/babel#10179 (comment) npm i --save-dev @babel/plugin-proposal-object-rest-spread is sufficient as a fix.
Just wanted to confirm for others struggling with this issue that @jenniferlynparsons recommendation fixed my issue.
Was fighting with our CI machine and followed many of the above suggestions, but a reboot finally fixed the issue. |
I had similar issue when I tried to upgrade babel to v7 and my unit test with jest failed with such error. Eventually, I found I had to set And I don't have to add |
Babel seems to need a specific package to support the `...` operator for now. See: babel/babel#10179 (comment) npm i --save-dev @babel/plugin-proposal-object-rest-spread is sufficient as a fix.
* Add reducer with some basic actions The reducer does define some actions, but never produces a different state. * Add function to initalize the data store for fresh-data * Add function to initialize the fresh-data API client * Add empty Payments API spec This will be filled in as we go, but can remain empty for now since we're not actually calling any Payments endpoints for data. * Add dependencies to package.json * Add function to initialize the Payments data store API * Include the fresh-data Payments data store in web app * Refactor TransactionsList to React Component class This is necessary to use the component with fresh-data. Currently the component always shows an empty table. * Add withSelect function This is used to wrap components before exporting them, and allows components to access the fresh-data data store. * Wrap TransactionsList export with `withSelect` This will allow us to access the fresh-data data store. * Add hard coded test data to transactions fresh-data selector The selector really shouldn't be using hard coded data, but this is for testing! All for the greater good, I'm sure. * Add transactions selector to the Payments API spec * Retrieve data to display in TransactionsList using transactions selector By retrieving the relevant selectors we can access the data from the fresh-data data store, and use that to populate the transactions table. As far as I understand this (@coderkevin would be a better person to ask) the `withSelect` method basically injects data from the selector into the component's `this.props`, allowing us to use the data in the component. * Update package-lock.json * Fix wrong parameter name in `createApiClient` * Add reducer for `fresh-data` * Add lodash to dependencies * Add read operation for transactions list This operation defines how requests are sent for `fresh-data` transactions resources, i.e. how the transactions list is retrieved. * Expose the transactions list 'read' operation to `fresh-data` * Add transactions list selector The selector can be used to retrieve transactions list for components. This commit also adapts the code to fit the new selector better. * Add code to determine if the table loading view should be displayed * Fix `getTransactionsLoading` function Incorrectly accessing the resource object caused the timestamps to be undefined when evaluating whether the transactions request is loading or not. * Update fresh-data version in package.json * Change loading status selector to not specify requirements * Export transactions operations to improve testability * Remove unnecessary setup code from fresh-data data store initialization * Add packages necessary to run tests For some reason jest can't find '@wordpress/api-fetch' unless it's installed. Even though the test doesn't actually _use_ api-fetch, it complains because one of the included files imports api-fetch. * Fix transactions operations * Add transactions operation tests * Add transactions selector tests * Merge changes to transactions-list.js from master * Add `showTransactionsPlaceholder` selector Used to indicate whether the `TableCard` in the transactions list should show the loading placeholder view or not. * Fix `...` (spread operator) missing error. Babel seems to need a specific package to support the `...` operator for now. See: babel/babel#10179 (comment) npm i --save-dev @babel/plugin-proposal-object-rest-spread is sufficient as a fix.
Babel seems to need a specific package to support the `...` operator for now. See: babel/babel#10179 (comment) npm i --save-dev @babel/plugin-proposal-object-rest-spread is sufficient as a fix.
* Add packages necessary to run tests For some reason jest can't find '@wordpress/api-fetch' unless it's installed. Even though the test doesn't actually _use_ api-fetch, it complains because one of the included files imports api-fetch. * Fix `...` (spread operator) missing error. Babel seems to need a specific package to support the `...` operator for now. See: babel/babel#10179 (comment) npm i --save-dev @babel/plugin-proposal-object-rest-spread is sufficient as a fix. * Fix transactions UI snapshot * Change from named test import to default import * Fix exports to accommodate snapshot tests * Configure jest and snapshot to use same timezone * Rename jest config files to better represent their purpose Renamed `setup-globals.js` to `jest-file-setup.js` to reflect the fact that it contains configurations run before each test file. Renamed `global-setup-jest.js` to `jest-global-setup.js` to fit the naming pattern used for the aforementioned rename. This file includes a global configuration run before each test suite.
Bug Report
Current Behavior
I've updated to 7.5 and have been following the developments with issues that should have been resolved with https://github.com/babel/babel/releases/tag/v7.5.1 however after stripping and reinstalling everything babel-related, I'm still getting this error.
Babel packages
@babel/cli: "^7.5.0"
@babel/core: "^7.5.0"
@babel/helpers: "^7.5.1"
@babel/plugin-proposal-object-rest-spread: "^7.5.1"
@babel/plugin-transform-runtime: "^7.5.0"
@babel/polyfill: "^7.4.4"
@babel/preset-env: "^7.5.0"
@babel/preset-react: "^7.0.0"
babel-eslint: "^10.0.2"
babel-jest: "^24.8.0"
babel-loader: "^8.0.6"
babel-plugin-dynamic-import-node: "^2.3.0"
babel-plugin-jsx-remove-data-test-id: "^2.0.0"
babel-plugin-transform-class-properties: "^6.24.1"
babel-plugin-transform-decorators-legacy: "^1.3.5"
babel-plugin-transform-export-extensions: "^6.22.0"
babel-plugin-transform-object-rest-spread: "^6.26.0"
Babel Configuration (.babelrc, package.json, cli command)
Environment
The text was updated successfully, but these errors were encountered: