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

How do I include jquery in this setpu? #981

Closed
Sireini opened this issue Oct 28, 2016 · 19 comments
Closed

How do I include jquery in this setpu? #981

Sireini opened this issue Oct 28, 2016 · 19 comments

Comments

@Sireini
Copy link

Sireini commented Oct 28, 2016

I want to use jqeury in my app.jsx but how do I include this to use?

@kasperpeulen
Copy link
Contributor

import $ from 'jquery';

npm i -S jquery

@Sireini
Copy link
Author

Sireini commented Oct 29, 2016

Thank you :) Iam going to try that. Maybe a bit of a stupid question but how can I use less and compile it easily.

@Sireini
Copy link
Author

Sireini commented Oct 29, 2016

After doing what you advised me I'll get this error: bundle.js:17 Uncaught TypeError: (0 , l.$) is not a function(…)

@gaearon
Copy link
Contributor

gaearon commented Oct 29, 2016

@smgjreinieren

After doing what you advised me I'll get this error: bundle.js:17 Uncaught TypeError: (0 , l.$) is not a function(…)

Which version of jQuery did you install? Importing it like this will only work with 2.x and later. If you still have issues can you please provide a project reproducing it?

how can I use less and compile it easily.

Just like you'd normally do: run Less command-line tool, and it will create a CSS file. Import that file like the user guide suggests.

@Sireini
Copy link
Author

Sireini commented Oct 30, 2016

@gaearon this is what is in my package.json: "jquery": "^3.1.1",

Thereby I allready have an bootstrap setup with gulp file to compile less but I dont know how to combine this with each other..

@gaearon
Copy link
Contributor

gaearon commented Oct 30, 2016

Please provide a project reproducing the problem.
It's hard to help otherwise.
Cheers!

@Sireini
Copy link
Author

Sireini commented Oct 30, 2016

@gaearon Do you have suggestions where I can reproduce it?

@gaearon
Copy link
Contributor

gaearon commented Oct 30, 2016

I mean: if you have any issues, please publish your project on GitHub so I can take a look.

@Sireini
Copy link
Author

Sireini commented Oct 31, 2016

@gaearon what I want to try is to combine these two project setups: https://github.com/smgjreinieren/React-bootstrap

@gaearon
Copy link
Contributor

gaearon commented Oct 31, 2016

@smgjreinieren Before I clone the repo, please can you tell what the issue is? Are you still seeing this: #981 (comment)? Or is there another problem?

@Sireini
Copy link
Author

Sireini commented Oct 31, 2016

@gaearon Nope allready fixed that but I want to use custom bootstrap with this setup. Not related to this issue maybe you could help me out

@viankakrisna
Copy link
Contributor

@smgjreinieren you don't need gulp to use less with create-react-app, you can just create another npm scripts inside package.json

for example, run
npm install --save-dev lessc && npm install --save-dev nodemon

and change your script section in package.json to

"scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "less": "nodemon -e less --exec \"lessc styles.less styles.min.css\"",
    "eject": "react-scripts eject"
}

run it with npm run less

I'm not really familiar with less command line tooling, I personally use sass ported bootstrap with node-sass because it has built it watch support (I use nodemon in above example, haven't really tested that).

@viankakrisna
Copy link
Contributor

whoops, saw the title. it's already out of topic. It's better to put your question in Stack Overflow

@gaearon
Copy link
Contributor

gaearon commented Nov 2, 2016

I want to use custom bootstrap with this setup

You can put any command in scripts in package.json, including a custom script, e.g.

  "compile-bootstrap": "node scripts/compile-bootstrap.js"

Then you can write node scripts/compile-bootstrap.js which spawns necessary Node commands or uses Node API to do any build steps you like, and outputs JS and/or CSS files you could import from your project's source code.

Since the original issue is solved, I'll close this one. Cheers!

@gaearon gaearon closed this as completed Nov 2, 2016
@Sireini
Copy link
Author

Sireini commented Nov 3, 2016

@gaearon How do you mean that? Iam not understand the new line clearly in package.json.. I tried to include the main.css and main.js in my index.html like this: <link rel="stylesheet" href="../../public/web/css/main.css">

but it seems not to find that styling.. What do you mean with write custom script what will it do?

@gaearon
Copy link
Contributor

gaearon commented Nov 3, 2016

I tried to include the main.css and main.js in my index.html like this: <link rel="stylesheet" href="../../public/web/css/main.css"

Does the user guide help?

You can use either way.

@Sireini
Copy link
Author

Sireini commented Nov 4, 2016

@gaearon That is really usefull thanks,

@faurenlarr
Copy link

I am also having an issue with jquery, similar to the one mentioned above. I imported a later than 2.x version and imported with import $ from 'jquery. I am receiving this error: The jQuery object is actually just the init constructor 'enhanced' // Need init if jQuery is called (just allow error to be thrown if not included) return new jQuery…

@gaearon
Copy link
Contributor

gaearon commented Sep 4, 2017

@faurenlarr Could you please provide a project reproducing the problem? It would also be great if you could file a separate issue because it’s hard to keep track of (usually unrelated) problems in old issues. Thanks!

@lock lock bot locked and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants