I recently wanted to shift my sample app created using react-create-app to an existing React project.
I am using the react-autosuggest library to render a simple search bar.
While exporting the files to my existing react project, I get the following error:
Module build failed: SyntaxError: Unexpected token (126:11)
124 | }
125 |
> 126 | onChange = (event, { newValue }) => {
| ^
127 | this.setState({
128 | value: newValue
129 | });
BabelLoaderError: SyntaxError: Unexpected token (126:11)
124 | }
125 |
> 126 | onChange = (event, { newValue }) => {
| ^
127 | this.setState({
128 | value: newValue
129 | });
The code is part of the react-autosuggest library
The only difference I see in the projects is their devDependencies, in package.json.
Here's the package.json for the project that's working:
{
"name": "autosuggestapp",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^15.6.1",
"react-autosuggest": "^9.2.0",
"react-dom": "^15.6.1"
},
"devDependencies": {
"react-scripts": "1.0.7"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
Here's the one that has the error:
{
"name": "my-app",
"version": "0.0.1",
"description": "my app",
"readme": "./README.md",
"dependencies": {
"babel-polyfill": "6.22.0",
"history": "4.5.1",
"invariant": "2.2.2",
"lodash": "4.17.4",
"node-sass": "^3.13.1",
"query-string": "4.3.1",
"react": "15.4.2",
"react-autosuggest": "^9.3.0",
"react-dom": "15.4.2",
"react-redux": "5.0.2",
"react-tooltip": "3.2.7",
"redux": "3.6.0",
"redux-saga": "0.14.3",
"reselect": "2.5.4",
"sn-http-request": "0.0.16"
},
"devDependencies": {
"babel-cli": "6.22.2",
"babel-core": "6.22.1",
"babel-eslint": "7.1.1",
"babel-loader": "6.2.10",
"babel-preset-es2015": "6.22.0",
"babel-preset-react": "6.22.0",
"babel-preset-stage-3": "6.17.0",
"case-sensitive-paths-webpack-plugin": "1.1.4",
"colors": "1.1.2",
"cross-env": "3.1.3",
"css-loader": "0.26.1",
"eslint": "3.14.1",
"eslint-loader": "1.6.1",
"eslint-plugin-import": "2.2.0",
"eslint-plugin-jsx-a11y": "3.0.2",
"eslint-plugin-react": "6.9.0",
"extract-text-webpack-plugin": "1.0.1",
"fs-extra": "0.30.0",
"glob": "7.1.1",
"jasmine-reporters": "2.2.0",
"jest": "18.1.0",
"jest-cli": "18.1.0",
"lodash-webpack-plugin": "0.11.0",
"mkdirp": "0.5.1",
"moment": "2.15.1",
"node-sass": "4.5.0",
"npm-run-all": "3.1.0",
"q": "1.4.1",
"replacestream": "4.0.2",
"sass-loader": "4.0.2",
"stringify-object": "3.1.0",
"through2": "2.0.1",
"watch": "1.0.1",
"webpack": "1.14.0",
"xml2js": "0.4.17",
"yargs": "6.0.0"
},
"repository": {
"type": "git",
"url": <my project's git url>
},
"engines": {
"node": ">=6.9.0"
},
"jest": {
"testPathIgnorePatterns": [
"/node_modules/",
"/target/"
],
"setupTestFrameworkScriptFile": "./tool/jasmine.env.js"
},
"scripts": {
"clean-target": "babel-node ./tool/build.cleanup.js",
"build:resources": "babel-node ./tool/buildResources.js",
"build:js": "babel-node ./tool/buildJs.js",
"intl": "babel-node ./tool/intl",
"build:intl": "npm-run-all build:resources intl",
"watch": "babel-node ./tool/watcher.js",
"watch-quick": "babel-node ./tool/watcher.js -q",
"prebuild": "npm run clean-target",
"build": "npm-run-all --parallel build:intl build:js",
"build:watch": "npm-run-all build:intl watch",
"start": "npm-run-all prebuild build:resources watch-quick",
"test": "echo 'Do not run jest until fixed'",
"test:watch": "npm run test -- --watch"
}
}
I think it is because you are using the Class instance fields syntax that is in stage-2, but you are using the Babel stage-3 preset (good idea to post your package.json!)
Check it out here. If you enable stage-2, you will see that the error goes away.
Related
My site is not mobile friendly when testing with Google Mobile friendly. But actually when accessing it, it is mobile friendly.
What should I do to fix it? I am using Next.js.
Result when I test: https://search.google.com/test/mobile-friendly/result?id=zwleJJ0VXRiIwFagHtBHuA
My package.json:
{
"name": "tintuc",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev -p 8080",
"build": "next build",
"start": "next start -p 8080",
"sitemap": "next-sitemap",
"analyze": "cross-env ANALYZE=true next build",
"analyze:server": "cross-env BUNDLE_ANALYZE=server next build",
"analyze:browser": "cross-env BUNDLE_ANALYZE=browser next build",
"find:unused": "next-unused",
"depcheck": "npx depcheck"
},
"dependencies": {
"#apollo/client": "^3.3.19",
"#headlessui/react": "^1.4.1",
"#heroicons/react": "^1.0.4",
"date-fns": "^2.25.0",
"deepmerge": "^4.2.2",
"graphql": "^15.5.0",
"highlight.js": "^11.6.0",
"html-react-parser": "^3.0.4",
"lodash": "^4.17.21",
"next": "^12.2.5",
"next-seo": "^4.28.1",
"node-html-parser": "^5.0.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-loading-skeleton": "^2.2.0",
"replace-special-characters": "^1.2.6"
},
"devDependencies": {
"#next/bundle-analyzer": "^11.1.4",
"#types/node": "^18.11.0",
"#types/react": "^18.0.21",
"autoprefixer": "^10.3.6",
"next-pwa": "^5.6.0",
"next-sitemap": "^3.1.29",
"next-unused": "^0.0.6",
"postcss": "^8.3.8",
"tailwindcss": "^2.2.16"
}
}
I am defined the functional properties in model like this:
export interface IIapProductProps {
iapproducts: IIapProductState,
dispatch: Dispatch
loading: boolean
}
and this is the model:
interface IIapProductModel {
namespace: 'iapproduct'
state: IIapProductState
reducers: {
getPage: Reducer<IIapProductState>,
getList: Reducer<IIapProductState>,
edit:Reducer<IIapProductState>,
add: Reducer<IIapProductState>,
}
effects: {
getIapProductPage: Effect,
getProductList: Effect,
editProduct: Effect,
addProduct: Effect
}
subscriptions: {
setup: Subscription
}
}
does the IIapProductProps first parameter name must be the same with the namespace's name? I found when I changed the namespace to iapproduct, the properties iapproducts must be the same with the model namespace. this is the package.json:
{
"name": "ant-design-pro",
"version": "5.2.0",
"private": true,
"description": "An out-of-box UI solution for enterprise applications",
"scripts": {
"analyze": "cross-env ANALYZE=1 umi build",
"build": "umi build",
"deploy": "npm run build && npm run gh-pages",
"dev": "npm run start:dev",
"gh-pages": "gh-pages -d dist",
"i18n-remove": "pro i18n-remove --locale=zh-CN --write",
"postinstall": "umi g tmp",
"lint": "umi g tmp && npm run lint:js && npm run lint:style && npm run lint:prettier && npm run tsc",
"lint-staged": "lint-staged",
"lint-staged:js": "eslint --ext .js,.jsx,.ts,.tsx ",
"lint:fix": "eslint --fix --cache --ext .js,.jsx,.ts,.tsx --format=pretty ./src && npm run lint:style",
"lint:js": "eslint --cache --ext .js,.jsx,.ts,.tsx --format=pretty ./src",
"lint:prettier": "prettier -c --write \"src/**/*\" --end-of-line auto",
"lint:style": "stylelint --fix \"src/**/*.less\" --syntax less",
"openapi": "umi openapi",
"playwright": "playwright install && playwright test",
"precommit": "lint-staged",
"prettier": "prettier -c --write \"src/**/*\"",
"serve": "umi-serve",
"start": "cross-env UMI_ENV=dev umi dev",
"start:dev": "cross-env REACT_APP_ENV=dev MOCK=none UMI_ENV=dev umi dev",
"start:no-mock": "cross-env MOCK=none UMI_ENV=dev umi dev",
"start:no-ui": "cross-env UMI_UI=none UMI_ENV=dev umi dev",
"start:pre": "cross-env REACT_APP_ENV=pre UMI_ENV=dev umi dev",
"start:test": "cross-env REACT_APP_ENV=test MOCK=none UMI_ENV=dev umi dev",
"test": "umi test",
"test:component": "umi test ./src/components",
"test:e2e": "node ./tests/run-tests.js",
"tsc": "tsc --noEmit"
},
"lint-staged": {
"**/*.less": "stylelint --syntax less",
"**/*.{js,jsx,ts,tsx}": "npm run lint-staged:js",
"**/*.{js,jsx,tsx,ts,less,md,json}": [
"prettier --write"
]
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 10"
],
"dependencies": {
"#ant-design/icons": "^4.7.0",
"#ant-design/pro-components": "^1.1.14",
"#ant-design/pro-descriptions": "^1.10.0",
"#ant-design/pro-form": "^1.52.0",
"#ant-design/pro-layout": "^6.32.0",
"#ant-design/pro-table": "2.72.1",
"#loadable/component": "^5.15.2",
"#types/crypto-js": "^4.1.1",
"#types/react-loadable": "^5.5.6",
"#umijs/route-utils": "^2.0.0",
"antd": "^4.17.0",
"classnames": "^2.3.0",
"crypto-js": "^4.1.1",
"dayjs": "^1.11.1",
"echarts": "^5.3.3",
"echarts-for-react": "^3.0.2",
"js-wheel": "https://github.com/jiangxiaoqiang/js-wheel.git",
"lodash": "^4.17.0",
"moment": "^2.29.0",
"omit.js": "^2.0.2",
"rc-menu": "^9.1.0",
"rc-util": "^5.16.0",
"react": "^17.0.0",
"react-dev-inspector": "^1.7.0",
"react-dom": "^17.0.0",
"react-helmet-async": "^1.2.0",
"react-loadable": "^5.5.0",
"react-native-aes-crypto": "^2.1.0",
"react-router": "^6.3.0",
"react-router-dom": "^6.3.0",
"umi": "3.5.0",
"umi-request": "^1.4.0",
"uuid": "^8.3.2"
},
"devDependencies": {
"#ant-design/pro-cli": "^2.1.0",
"#playwright/test": "^1.17.0",
"#types/express": "^4.17.0",
"#types/history": "^4.7.0",
"#types/jest": "^26.0.0",
"#types/lodash": "^4.14.0",
"#types/react": "^17.0.0",
"#types/react-dom": "^17.0.0",
"#types/react-helmet": "^6.1.0",
"#types/react-router": "^5.1.18",
"#types/react-router-dom": "^5.3.3",
"#umijs/fabric": "^2.8.0",
"#umijs/openapi": "^1.3.0",
"#umijs/plugin-blocks": "^2.2.0",
"#umijs/plugin-esbuild": "^1.4.0",
"#umijs/plugin-openapi": "^1.3.0",
"#umijs/preset-ant-design-pro": "^1.3.0",
"#umijs/preset-dumi": "^1.1.0",
"#umijs/preset-react": "^1.8.17",
"#umijs/yorkie": "^2.0.5",
"carlo": "^0.9.46",
"cross-env": "^7.0.0",
"cross-port-killer": "^1.3.0",
"detect-installer": "^1.0.0",
"enzyme": "^3.11.0",
"eslint": "^7.32.0",
"express": "^4.17.0",
"gh-pages": "^3.2.0",
"jsdom-global": "^3.0.0",
"lint-staged": "^10.0.0",
"mockjs": "^1.1.0",
"prettier": "^2.5.0",
"puppeteer-core": "^8.0.0",
"stylelint": "^13.0.0",
"swagger-ui-react": "^4.12.0",
"typescript": "^4.5.0",
"umi-serve": "^1.9.10"
},
"engines": {
"node": ">=10.0.0"
},
"gitHooks": {
"commit-msg": "fabric verify-commit"
}
}
Current Behavior
Getting semicolon missing error only on publish to storybook-to-ghpages step.
Expected Behavior
Should deploy the stories to GitHub pages.
Steps to Reproduce
Create a new nx workspace.
Create two new react libraries using nx console vs code extension.
Running storybook locally works fine using nx run project-name:storybook.
When trying to deploy to github pages using npx -p #storybook/storybook-deployer storybook-to-ghpages you will get missing semicolon error.
You can also watch this youtube video to see how to reproduce:
https://www.youtube.com/watch?v=c323HOuFKkA
Our package.json at the root:
{
"name": "cxc-react-monorepo",
"version": "0.0.0",
"private": true,
"scripts": {
"prepare": "husky install",
"start": "nx serve",
"build": "nx run-many --target=build --all",
"build:icons": "nx run cxc-react-icons:build-icons",
"test": "nx run-many --target=test --all",
"graph": "nx graph",
"lint": "nx workspace-lint && nx lint",
"e2e": "nx e2e",
"affected:libs": "nx affected:libs",
"affected:build": "nx affected:build",
"affected:e2e": "nx affected:e2e",
"affected:test": "nx affected:test",
"affected:lint": "nx affected:lint",
"affected:graph": "nx affected:graph",
"commit": "git cz",
"version": "lerna version",
"version:beta": "lerna version --conventional-prerelease",
"release:ci": "lerna publish from-package"
},
"dependencies": {
"#ford/ford-design-system": "^18.3.0",
"axios": "^0.27.2",
"clsx": "^1.1.1",
"core-js": "^3.6.5",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-hook-form": "^7.31.3",
"regenerator-runtime": "0.13.7",
"tslib": "^2.3.0",
"valtio": "^1.6.0"
},
"devDependencies": {
"#nrwl/cli": "14.1.4",
"#nrwl/cypress": "14.1.4",
"#nrwl/eslint-plugin-nx": "14.1.4",
"#nrwl/jest": "14.1.4",
"#nrwl/linter": "14.1.4",
"#nrwl/react": "14.1.4",
"#nrwl/web": "14.1.4",
"#nrwl/workspace": "14.1.4",
"#testing-library/jest-dom": "^5.16.4",
"#testing-library/react": "^13.2.0",
"#testing-library/user-event": "^14.2.0",
"#types/jest": "27.4.1",
"#types/node": "16.11.7",
"#types/react": "18.0.8",
"#types/react-dom": "18.0.3",
"#types/react-modal": "^3.13.1",
"#typescript-eslint/eslint-plugin": "~5.18.0",
"#typescript-eslint/parser": "~5.18.0",
"babel-jest": "27.5.1",
"chalk": "^2.4.1",
"cypress": "^9.1.0",
"cz-conventional-changelog": "^3.3.0",
"eslint": "~8.12.0",
"eslint-config-prettier": "8.1.0",
"eslint-plugin-cypress": "^2.10.3",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-jsx-a11y": "6.5.1",
"eslint-plugin-react": "7.29.4",
"eslint-plugin-react-hooks": "4.5.0",
"husky": "^8.0.1",
"jest": "27.5.1",
"lerna": "^4.0.0",
"nx": "14.1.4",
"prettier": "^2.5.1",
"react-modal": "^3.15.1",
"react-test-renderer": "^18.1.0",
"shelljs": "^0.8.2",
"svgr": "^1.10.0",
"ts-jest": "27.1.4",
"ts-node": "9.1.1",
"typescript": "~4.6.2"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}
Failure Logs
RROR in
src/stories/Button.stories.tsx
Line 13:2: Parsing error: Missing semicolon
11 | backgroundColor: { control: 'color' },
12 | },
> 13 | } as Meta;
| ^
14 |
15 | const Template: Story<ButtonProps> = (args) => <Button {...args} />;
16 |
Environment
nx : 14.1.9
#nrwl/angular : Not Found
#nrwl/cypress : 14.1.9
#nrwl/detox : Not Found
#nrwl/devkit : 14.1.9
#nrwl/eslint-plugin-nx : 14.1.9
#nrwl/express : Not Found
#nrwl/jest : 14.1.9
#nrwl/js : 14.1.9
#nrwl/linter : 14.1.9
#nrwl/nest : Not Found
#nrwl/next : Not Found
#nrwl/node : Not Found
#nrwl/nx-cloud : Not Found
#nrwl/nx-plugin : Not Found
#nrwl/react : 14.1.9
#nrwl/react-native : Not Found
#nrwl/schematics : Not Found
#nrwl/storybook : 14.1.9
#nrwl/web : 14.1.9
#nrwl/workspace : 14.1.4
typescript : 4.6.4
rxjs : 6.6.7
I just started a new project using React with Webpack. I keep getting the same error when serving the app.
Uncaught Error: Module build failed: Error: ENOENT: no such file or directory, open 'C:\workwork\apol2\apol2\node_modules\webpack\buildin\global.js'
at Object. (tiny-warning.esm.js:20)
at webpack_require (bootstrap 73c6a5b3e608efed68ac:19)
at Object. (scheduler.development.js:699)
at webpack_require (bootstrap 73c6a5b3e608efed68ac:19)
at Object. (index.js:6)
at Object. (index.js:7)
at webpack_require (bootstrap 73c6a5b3e608efed68ac:19)
at react-dom.development.js:21
at Object. (react-dom.development.js:21277)
at Object. (react-dom.development.js:21278)
This is not a package I installed and I don't know where to begin to debug this.. Could it be one of the package I use?
{
"name": "demo",
"version": "1.0.0",
"description": "",
"scripts": {
"build": "babel ./app -d build",
"build:watch": "babel ./app -d build --watch",
"build:client": "webpack --config ./webpack.config.js/",
"build:watch:client": "webpack --config ./webpack.config.js/ --watch",
"build:prod": "npm run build && npm run build:client",
"start": "npm run build:prod && NODE_ENV=production node ./build/server/index.js",
"start:dev": "parallelshell \"npm run build:watch\" \"npm run build:watch:client\" \"nodemon ./build/server/index.js\"",
"test": "jest --watch --coverage"
},
"author": "",
"license": "ISC",
"jest": {
"testMatch": [
"**/?(*.)+(spec|test).[jt]s?(x)"
],
"testPathIgnorePatterns": [
"/build/"
],
"modulePathIgnorePatterns": [
"/build/"
],
"snapshotSerializers": [
"enzyme-to-json/serializer"
],
"coverageThreshold": {
"global": {
"branches": 90,
"functions": 90,
"lines": 90,
"statements": 90
}
},
"setupFilesAfterEnv": [
"<rootDir>setupTests.js"
]
},
"dependencies": {
"#babel/cli": "^7.5.5",
"#babel/core": "^7.5.5",
"#babel/preset-env": "^7.5.5",
"#babel/preset-react": "^7.0.0",
"assert": "^2.0.0",
"axios": "^0.19.0",
"babel-loader": "^8.0.6",
"cors": "^2.8.4",
"express": "^4.15.3",
"fs": "0.0.2",
"html-webpack-plugin": "^3.2.0",
"https": "^1.0.0",
"mongodb": "^3.3.0-beta2",
"parallelshell": "^3.0.1",
"react": "^16.8.6",
"react-dom": "^16.10.2",
"react-router-dom": "^5.0.1",
"scheduler": "^0.16.2",
"webpack": "^4.41.1"
},
"devDependencies": {
"babel-jest": "^24.8.0",
"enzyme": "^3.10.0",
"enzyme-adapter-react-16": "^1.14.0",
"enzyme-to-json": "^3.3.5",
"eslint": "^6.1.0",
"eslint-config-airbnb": "^17.1.1",
"eslint-plugin-import": "^2.11.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.7.0",
"jest": "^24.8.0",
"nodemon": "^1.11.0",
"react-test-renderer": "^16.8.6",
"supertest": "^4.0.2"
}
}
After deleting my folder node_modules several times between my tests, the error disapeared...
Webpack is not installed, make sure install webpack or do npm install
I deployed a next.js application to the App Engine Standard and I get 500 error. In StackDriver the error is "/bin/sh: 1: server.js: not found"
but server.js exists in the app:
I'm serving up my project on port 3000
Package.json is like this:
{
"name": "supplychain",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha",
"dev": "node server.js",
"start": "NODE_ENV=production server.js",
"transpile": "babel src -d dist --copy-files",
"prepublishOnly": "npm run transpile",
"build": "next build",
"deploy": "gh-pages -d examples/dist",
},
"author": "",
"license": "ISC",
"dependencies": {
"#babel/polyfill": "^7.2.5",
"fs-extra": "^7.0.1",
"ganache-cli": "^6.4.1",
"mocha": "^5.2.0",
"next": "^4.1.1",
"next-routes": "^1.4.2",
"radium": "^0.25.1",
"react": "^16.8.4",
"react-dom": "^16.8.4",
"semantic-ui-react": "^0.82.5",
"solc": "^0.4.25",
"truffle-hdwallet-provider": "0.0.3",
"web3": "^1.0.0-beta.35"
},
"devDependencies": {
"#babel/cli": "^7.2.3",
"#babel/core": "^7.2.2",
"#babel/preset-env": "^7.3.1",
"babel": "^6.23.0",
"babel-cli": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"css-loader": "^2.1.0",
"html-webpack-plugin": "^3.2.0",
"npm-install-webpack-plugin": "^4.0.5",
"terser-webpack-plugin": "^1.3.0",
"uglifyjs-webpack-plugin": "v1.0.0-beta.1",
"webpack": "^4.35.0",
"webpack-cli": "^3.3.4",
"webpack-dev-server": "^3.7.2"
}
}
and app.yaml is like:
# [START app_yaml]
runtime: nodejs8
# [END app_yaml]
Can somebody help me find the problem?
Change this line:
"start": "NODE_ENV=production server.js",
To:
"start": "NODE_ENV=production node server.js",