Skip to content
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

Having an error after creating production build of a project #39

Closed
Okami92 opened this issue Jul 25, 2018 · 10 comments
Closed

Having an error after creating production build of a project #39

Okami92 opened this issue Jul 25, 2018 · 10 comments

Comments

@Okami92
Copy link

Okami92 commented Jul 25, 2018

in dev mode, everything works fine, but when making production build, I am having this error:

http://prntscr.com/katck3

is there a reason why this can happen? I am using 2.0.0-beta-3 of react-to-print and webpack 4.6.0

@gregnb
Copy link
Collaborator

gregnb commented Jul 25, 2018

Hey @Okami92 sorry to hear that. Can you try visiting: https://kmmw7l39y7.codesandbox.io/#

Does that work for you?

@Okami92
Copy link
Author

Okami92 commented Jul 25, 2018

@gregnb yes, this works. could you please help me with my issue? do you have any ideas how this is possible?

http://prntscr.com/kau111

not sure what is wrong here

@gregnb
Copy link
Collaborator

gregnb commented Jul 25, 2018

Could you paste me your package.json and also is there any chance you could share the portion of your app that does the printing into a separate repo so we could look into it? more than happy to help

@Okami92
Copy link
Author

Okami92 commented Jul 25, 2018

@gregnb sure, thanks a lot! I'll prepare separate repo for you in a moment

  "name": "",
  "version": "1.0.0",
  "description": "npm i -g prettier",
  "main": "index.js",
  "scripts": {
    "clean": "rimraf dist",
    "dev": "cross-env NODE_ENV=development node devServer.js",
    "build": "npm run clean && cross-env NODE_ENV=production webpack --config=webpack.build.config.js -p && node productionServer.js",
    "flow": "flow"
  },
  "author": "",
  "license": "ISC",
  "browserslist": [
    "last 5 versions",
    "not ie < 11"
  ],
  "prettier": {
    "singleQuote": true,
    "trailingComma": "all"
  },
  "dependencies": {
    "axios": "^0.18.0",
    "babel-plugin-styled-components": "^1.5.1",
    "es6-promise": "^4.2.4",
    "prop-types": "^15.6.1",
    "qs": "^6.5.2",
    "react": "^16.3.2",
    "react-custom-scrollbars": "^4.2.1",
    "react-dnd": "^3.0.2",
    "react-dnd-touch-backend": "^0.4.0",
    "react-dom": "^16.3.2",
    "react-motion": "^0.5.2",
    "react-redux": "^5.0.7",
    "react-router-dom": "^4.2.2",
    "react-slick": "^0.23.1",
    "react-to-print": "^2.0.0-beta-3",
    "redux": "^4.0.0",
    "redux-thunk": "^2.2.0",
    "slick-carousel": "^1.8.1",
    "styled-components": "^3.2.6",
    "xml2js": "^0.4.19"
  },
  "devDependencies": {
    "autoprefixer": "^8.3.0",
    "babel-core": "^6.26.0",
    "babel-eslint": "^8.2.3",
    "babel-loader": "^7.1.4",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "babel-plugin-transform-object-rest-spread": "^6.26.0",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-env": "^1.6.1",
    "babel-preset-flow": "^6.23.0",
    "babel-preset-react": "^6.24.1",
    "browserslist": "^3.2.4",
    "compression-webpack-plugin": "^1.1.11",
    "cross-env": "^5.1.4",
    "css-loader": "^0.28.11",
    "eslint": "^4.19.1",
    "eslint-config-airbnb": "^16.1.0",
    "eslint-config-prettier": "^2.9.0",
    "eslint-plugin-import": "^2.11.0",
    "eslint-plugin-jsx-a11y": "^6.0.3",
    "eslint-plugin-prettier": "^2.6.0",
    "eslint-plugin-react": "^7.7.0",
    "express": "^4.16.3",
    "extract-text-webpack-plugin": "^4.0.0-beta.0",
    "file-loader": "^1.1.11",
    "flow-bin": "^0.70.0",
    "html-webpack-plugin": "^3.2.0",
    "image-webpack-loader": "^4.2.0",
    "node-sass": "^4.8.3",
    "postcss-loader": "^2.1.4",
    "prettier-eslint": "^8.8.1",
    "react-hot-loader": "^4.0.0",
    "rimraf": "^2.6.2",
    "sass-loader": "^7.0.1",
    "style-loader": "^0.20.3",
    "url-loader": "^1.0.1",
    "webpack": "^4.6.0",
    "webpack-cli": "^2.1.2",
    "webpack-dev-middleware": "^3.1.2",
    "webpack-hot-middleware": "^2.22.1"
  }
}

@gregnb
Copy link
Collaborator

gregnb commented Jul 25, 2018

Great sounds good!

@Okami92
Copy link
Author

Okami92 commented Jul 25, 2018

@gregnb done: https://github.com/Okami92/print-error

npm i, npm run build - you'll see an error.

when npm run dev, it works fine.

@gregnb
Copy link
Collaborator

gregnb commented Jul 25, 2018

Ok I will try to look at this when I get some time today. Thank you

@gregnb
Copy link
Collaborator

gregnb commented Jul 26, 2018

Ok, so this issue comes from the fact that stateless components do not have refs:
facebook/react#4936

If you were to change your Printable component to a stateful component (ie: class Printable extends React.component) then this library will be able to attach to that ref.

I will look to add a warning into the library if the component to print happens to be stateless

@Okami92
Copy link
Author

Okami92 commented Jul 26, 2018

Yes, it works! Thanks a lot man! I wouldn't think about it without you 👍

@gregnb
Copy link
Collaborator

gregnb commented Jul 26, 2018

No problem!

@gregnb gregnb closed this as completed Jul 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants