runreflect / webpack-react-component-name

Webpack plugin that makes your custom React components visible within React Dev Tools and accessible by the React selector logic built into Reflect
MIT License
18 stars 7 forks source link

Unexpected Token while building #29

Open kyin42 opened 2 years ago

kyin42 commented 2 years ago

I had this issue with a larger code base where App isn't defined after being built. I've replicated the error in a new minimized code. I'm assuming it has something to do with the definition of App. My current code is as follows

function App() {
  return <div>simple app</div>;
}

export default App;

and it gives me the following build error

Unexpected token (1:205)
| function App(){return/*#__PURE__*/__WEBPACK_MODULE_REFERENCE__3_5b226a7378225d_call_directImport_asiSafe1__._("div",{children:"simple app"});}/* harmony default export */ var __WEBPACK_DEFAULT_EXPORT__ = (;try{App.displayName="App";}catch(e){}App);

if it helps my code is a simple create-react-app after ejection with webpack-react-compoonent-name added to the webpack nothing else was changed

tmcneal commented 2 years ago

Thank you for reporting @kyin42! Would you mind confirming that the version of webpack-react-component-name you're using is compatible with the version of Webpack within your app? For Webpack 4 you'll want to use version 4.x of our plugin, and for Webpack 5 you'll want to use version 5.x.

kyin42 commented 2 years ago

yea, no problem webpack is on 5.64.4 and webpack-react-component-name is on 5.0.4 here is my package.json if it helps

{
  "name": "test",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@babel/core": "^7.16.0",
    "@pmmmwh/react-refresh-webpack-plugin": "^0.5.3",
    "@svgr/webpack": "^5.5.0",
    "@testing-library/jest-dom": "^5.16.4",
    "@testing-library/react": "^13.3.0",
    "@testing-library/user-event": "^13.5.0",
    "babel-jest": "^27.4.2",
    "babel-loader": "^8.2.3",
    "babel-plugin-named-asset-import": "^0.3.8",
    "babel-preset-react-app": "^10.0.1",
    "bfj": "^7.0.2",
    "browserslist": "^4.18.1",
    "camelcase": "^6.2.1",
    "case-sensitive-paths-webpack-plugin": "^2.4.0",
    "css-loader": "^6.5.1",
    "css-minimizer-webpack-plugin": "^3.2.0",
    "dotenv": "^10.0.0",
    "dotenv-expand": "^5.1.0",
    "eslint": "^8.3.0",
    "eslint-config-react-app": "^7.0.1",
    "eslint-webpack-plugin": "^3.1.1",
    "file-loader": "^6.2.0",
    "fs-extra": "^10.0.0",
    "html-webpack-plugin": "^5.5.0",
    "identity-obj-proxy": "^3.0.0",
    "jest": "^27.4.3",
    "jest-resolve": "^27.4.2",
    "jest-watch-typeahead": "^1.0.0",
    "mini-css-extract-plugin": "^2.4.5",
    "postcss": "^8.4.4",
    "postcss-flexbugs-fixes": "^5.0.2",
    "postcss-loader": "^6.2.1",
    "postcss-normalize": "^10.0.1",
    "postcss-preset-env": "^7.0.1",
    "prompts": "^2.4.2",
    "react": "^18.2.0",
    "react-app-polyfill": "^3.0.0",
    "react-dev-utils": "^12.0.1",
    "react-dom": "^18.2.0",
    "react-refresh": "^0.11.0",
    "resolve": "^1.20.0",
    "resolve-url-loader": "^4.0.0",
    "sass-loader": "^12.3.0",
    "semver": "^7.3.5",
    "source-map-loader": "^3.0.0",
    "style-loader": "^3.3.1",
    "tailwindcss": "^3.0.2",
    "terser-webpack-plugin": "^5.2.5",
    "web-vitals": "^2.1.4",
    "webpack": "^5.64.4",
    "webpack-dev-server": "^4.6.0",
    "webpack-manifest-plugin": "^4.0.2",
    "webpack-react-component-name": "^5.0.4",
    "workbox-webpack-plugin": "^6.4.1"
  },
  "scripts": {
    "start": "node scripts/start.js",
    "build": "node scripts/build.js",
    "test": "node scripts/test.js"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "jest": {
    "roots": [
      "<rootDir>/src"
    ],
    "collectCoverageFrom": [
      "src/**/*.{js,jsx,ts,tsx}",
      "!src/**/*.d.ts"
    ],
    "setupFiles": [
      "react-app-polyfill/jsdom"
    ],
    "setupFilesAfterEnv": [
      "<rootDir>/src/setupTests.js"
    ],
    "testMatch": [
      "<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}",
      "<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}"
    ],
    "testEnvironment": "jsdom",
    "transform": {
      "^.+\\.(js|jsx|mjs|cjs|ts|tsx)$": "<rootDir>/config/jest/babelTransform.js",
      "^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
      "^(?!.*\\.(js|jsx|mjs|cjs|ts|tsx|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
    },
    "transformIgnorePatterns": [
      "[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|cjs|ts|tsx)$",
      "^.+\\.module\\.(css|sass|scss)$"
    ],
    "modulePaths": [],
    "moduleNameMapper": {
      "^react-native$": "react-native-web",
      "^.+\\.module\\.(css|sass|scss)$": "identity-obj-proxy"
    },
    "moduleFileExtensions": [
      "web.js",
      "js",
      "web.ts",
      "ts",
      "web.tsx",
      "tsx",
      "json",
      "web.jsx",
      "jsx",
      "node"
    ],
    "watchPlugins": [
      "jest-watch-typeahead/filename",
      "jest-watch-typeahead/testname"
    ],
    "resetMocks": true
  },
  "babel": {
    "presets": [
      "react-app"
    ]
  }
}
tmcneal commented 2 years ago

Great thanks! I'll take a look into what's going on.

Twipped commented 1 year ago

I also ran into this problem, but only when building for prod (with minification). It works fine building for dev.

It appears to be an off by one error when inserting the block.

f;try{BusinessEntityGate.displayName="BusinessEntityGate";}catch(e){}unction DirectRoutes()
tmcneal commented 1 year ago

Hey @Twipped thanks for reporting. Could you share what version of Webpack you're using as well as what version of this plugin you're using?

Also for the component that's exhibiting this issue, is it defined like the component that OP shared?

function App() {
  return <div>simple app</div>;
}

export default App;
Twipped commented 1 year ago

I can confirm that removing the + 1 on this line solved the problem.

webpack@5.88.2 webpack-react-component-name@5.0.5

And yes, same syntax.