Using `react-bootstrap` with `npm` - javascript
I want to create a project using npm, and want to use react-bootstrap inside it. I have package.json with the following dependencies.
{
"name": "simple-webapp",
"version": "0.0.1",
"description": "",
"scripts": {
"build": "gulp build",
"watch": "gulp watch --color",
"test": "echo \"This project doesn't have any tests.\" && exit 0"
},
"author": "",
"license": "ISC",
"devDependencies": {
"gulp": "3.8.11",
"qwest": "^1.5.12",
"react": "0.13.2",
"syrup": "0.1.14",
"bootstrap": "3.3.5",
"react-bootstrap": "0.13.3",
"react-router": "0.13.3"
}
}
When I run npm install I get:
npm WARN package.json simple-webapp#0.0.1 No description
npm WARN package.json simple-webapp#0.0.1 No repository field.
npm WARN package.json simple-webapp#0.0.1 No README data
> fsevents#0.3.6 install /Users/i-danielk/ideaProjects/webapi_bootstrap/webapp/node_modules/syrup/node_modules/watchify/node_modules/chokidar/node_modules/fsevents
> node-gyp rebuild
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
SOLINK_MODULE(target) Release/.node
SOLINK_MODULE(target) Release/.node: Finished
CXX(target) Release/obj.target/fse/fsevents.o
SOLINK_MODULE(target) Release/fse.node
SOLINK_MODULE(target) Release/fse.node: Finished
qwest#1.7.0 node_modules/qwest
react-bootstrap#0.13.3 node_modules/react-bootstrap
react-router#0.13.3 node_modules/react-router
├── object-assign#2.1.1
└── qs#2.4.1
gulp#3.8.11 node_modules/gulp
├── pretty-hrtime#0.2.2
├── interpret#0.3.10
├── deprecated#0.0.1
├── archy#1.0.0
├── minimist#1.1.1
├── tildify#1.1.0 (os-homedir#1.0.0)
├── v8flags#2.0.7 (user-home#1.1.1)
├── semver#4.3.6
├── chalk#0.5.1 (ansi-styles#1.1.0, escape-string-regexp#1.0.3, supports-color#0.2.0, has-ansi#0.1.0, strip-ansi#0.3.0)
├── orchestrator#0.3.7 (stream-consume#0.1.0, sequencify#0.0.7, end-of-stream#0.1.5)
├── gulp-util#3.0.5 (array-differ#1.0.0, array-uniq#1.0.2, lodash._reescape#3.0.0, lodash._reevaluate#3.0.0, beeper#1.1.0, lodash._reinterpolate#3.0.0, object-assign#2.1.1, replace-ext#0.0.1, vinyl#0.4.6, chalk#1.0.0, lodash.template#3.6.1, through2#0.6.5, multipipe#0.1.2, dateformat#1.0.11)
├── liftoff#2.1.0 (extend#2.0.1, rechoir#0.6.1, flagged-respawn#0.3.1, resolve#1.1.6, findup-sync#0.2.1)
└── vinyl-fs#0.3.13 (graceful-fs#3.0.8, strip-bom#1.0.0, defaults#1.0.2, vinyl#0.4.6, mkdirp#0.5.1, through2#0.6.5, glob-stream#3.1.18, glob-watcher#0.0.6)
bootstrap#3.3.5 node_modules/bootstrap
react#0.13.2 node_modules/react
└── envify#3.4.0 (through#2.3.7, jstransform#10.1.0)
syrup#0.1.14 node_modules/syrup
├── minimist#1.1.0
├── q#1.0.1
├── run-sequence#1.0.2 (chalk#1.0.0)
├── jshint-stylish#1.0.0 (text-table#0.2.0, string-length#1.0.0, chalk#0.5.1, log-symbols#1.0.2)
├── vinyl-source-stream#1.1.0 (vinyl#0.4.6, through2#0.6.5)
├── gulp-plumber#1.0.0 (through2#0.6.5)
├── gulp-replace#0.5.3 (istextorbinary#1.0.2, replacestream#2.0.0, through2#0.6.3)
├── gulp-sourcemaps#1.5.1 (graceful-fs#3.0.8, convert-source-map#1.1.1, strip-bom#1.0.0, vinyl#0.4.6, through2#0.6.5)
├── vinyl-buffer#1.0.0 (through2#0.6.5, bl#0.9.4)
├── del#0.1.3 (is-path-cwd#1.0.0, each-async#1.1.1, is-path-in-cwd#1.0.0, globby#0.1.1, rimraf#2.4.0)
├── gulp-if#1.2.5 (through2#0.6.5, gulp-match#0.2.1, ternary-stream#1.2.3)
├── express#4.10.1 (merge-descriptors#0.0.2, utils-merge#1.0.0, cookie#0.1.2, fresh#0.2.4, escape-html#1.0.1, range-parser#1.0.2, cookie-signature#1.0.5, finalhandler#0.3.2, vary#1.0.0, media-typer#0.3.0, methods#1.1.0, parseurl#1.3.0, serve-static#1.7.2, content-disposition#0.5.0, path-to-regexp#0.1.3, depd#1.0.1, qs#2.3.2, on-finished#2.1.1, debug#2.1.3, etag#1.5.1, proxy-addr#1.0.8, send#0.10.1, accepts#1.1.4, type-is#1.5.7)
├── gulp-util#3.0.1 (lodash._reinterpolate#2.4.1, vinyl#0.4.6, chalk#0.5.1, lodash.template#2.4.1, through2#0.6.5, multipipe#0.1.2, dateformat#1.0.11, lodash#2.4.2)
├── watchify#2.4.0 (through2#0.5.1, chokidar#0.12.6)
├── gulp-uglify#1.1.0 (deepmerge#0.2.10, through2#0.6.5, vinyl-sourcemaps-apply#0.1.4, uglify-js#2.4.16)
├── gulp-cache-breaker#0.0.3 (gulp-replace#0.4.0, checksum#0.1.1, request#2.58.0)
├── stringify#3.1.0 (through#2.3.7, stream-spec#0.3.5, html-minifier#0.6.9)
├── browserify#9.0.3 (https-browserify#0.0.0, tty-browserify#0.0.0, builtins#0.0.7, constants-browserify#0.0.1, process#0.10.1, path-browserify#0.0.0, os-browserify#0.1.2, isarray#0.0.1, inherits#2.0.1, commondir#0.0.1, string_decoder#0.10.31, stream-browserify#1.0.0, defined#0.0.0, has#1.0.0, shell-quote#0.0.1, subarg#1.0.0, domain-browser#1.1.4, xtend#3.0.0, shallow-copy#0.0.1, duplexer2#0.0.2, deep-equal#1.0.0, querystring-es3#0.2.1, assert#1.3.0, punycode#1.2.4, util#0.10.3, through2#1.1.1, events#1.0.2, timers-browserify#1.4.1, concat-stream#1.4.10, parents#1.0.1, console-browserify#1.1.0, vm-browserify#0.0.4, http-browserify#1.7.0, readable-stream#1.1.13, shasum#1.0.1, url#0.10.3, resolve#1.1.6, browser-resolve#1.9.0, labeled-stream-splicer#1.0.2, buffer#3.2.2, glob#4.5.3, JSONStream#0.10.0, deps-sort#1.3.9, syntax-error#1.1.4, browser-pack#4.0.4, crypto-browserify#3.9.14, insert-module-globals#6.5.0, browserify-zlib#0.1.4, module-deps#3.8.1)
├── griddle#0.1.2 (sane#0.8.1, handlebars#2.0.0)
├── gulp-react#3.0.1 (object-assign#2.1.1, through2#0.6.5, vinyl-sourcemaps-apply#0.1.4, react-tools#0.13.3)
├── gulp-jshint#1.9.0 (minimatch#1.0.0, through2#0.6.5, lodash#2.4.2, rcloader#0.1.4, jshint#2.8.0)
├── gulp-autoprefixer#1.0.1 (object-assign#1.0.0, through2#0.6.5, vinyl-sourcemaps-apply#0.1.4, autoprefixer-core#3.1.2)
├── babelify#6.0.1 (through#2.3.4, lodash#3.9.3, babel-core#5.5.8)
└── gulp-less#1.3.6 (convert-source-map#0.4.1, lodash.defaults#2.4.1, through2#0.5.1, vinyl-sourcemaps-apply#0.1.4, less#1.7.5)
Is it successfully installed?
Inside my app/main.jsx I have a button:
<Button bsStyle="success" bsSize="small" onClick={someCallback}>
Something
</Button>
When I run npm run build, I get:
/Users/i-danielk/ideaProjects/webapi_bootstrap/webapp/app/main.js
line 27 col 33 'Button' is not defined.
line 27 col 88 'someCallback' is not defined.
Where I am doing it wrong?
Looks like the install worked. What's causing your errors is that you did not require react-bootstrap so Button is undefined. The other error is just that you forgot to add this (has to be onClick={this.someCallback} where someCallback needs to be in your React Component.
To import react-browserifies Button you need to add
var Button = require('react-bootstrap').Button
to your app.jsx file
Related
how i can read file from vscode extension src
i want to read file from my src path, but i failed, i can only read file from absolute path, not from my src relatively path, this is my code , low is tree , my code is in src/ i want to read file in ../jsconfig/*.json, but it not work │ ├─.vscode │ extensions.json │ launch.json │ tasks.json │ ├─images │ anzhuang.jpg │ ├─jsconfig │ BHDZ.json │ BHJG.json | default.json │ ├─media │ code.js │ codicon.ttf │ index.html │ jsconfig.json │ style.css │ ├─pic │ icon.jfif │ ├─src │ dbfCustomEditor.js │ dbfDocument.js │ dbfEditorProvider.js │ extension.js │ └─test function matchJsonFile(dbfName){ var patten1 = dbfName.slice(0, -4) var patten2 = dbfName var res = "../default.json" for (var i=0;i<jsonFiles.length;i++){ if (jsonFiles[i].search(patten1) >= 0){ res = jsonFiles[i] break } if (jsonFiles[i].search(patten2) >= 0){ res = jsonFiles[i] break } } return res }
SWC: module item found but is_es6 is false
I'm trying to move from babel to swc for compiling and bundling a react component library but I have trouble with the configuration. When I run npm run spack, I get the following error: thread '<unnamed>' panicked at 'internal error: entered unreachable code: module item found but is_es6 is false: ExportNamed(NamedExport { span: Span { lo: BytePos(954874), hi: BytePos(954914), ctxt: #0 }, specifiers: [Named(ExportNamedSpecifier { span: Span { lo: BytePos(954883), hi: BytePos(954890), ctxt: #0 }, orig: Ident(Ident { span: Span { lo: BytePos(954883), hi: BytePos(954890), ctxt: #4141 }, sym: Atom('default' type=static), optional: false }), exported: Some(Ident(Ident { span: Span { lo: BytePos(954883), hi: BytePos(954890), ctxt: #194 }, sym: Atom('default' type=static), optional: false })), is_type_only: false })], src: Some(Str { span: Span { lo: BytePos(954898), hi: BytePos(954913), ctxt: #0 }, value: Atom('./FormControl' type=dynamic), raw: Some(Atom(''./FormControl'' type=dynamic)) }), type_only: false, asserts: None })', crates/swc_bundler/src/bundler/chunk/cjs.rs:142:29 What I get from this error is that he fails to bundle React components. I can't find the is_es6 configuration mentioned in the error so I'm not sure how to solve this. I tried rereading the doc of swc without any success. The module part of the config doesn't seem to solve my problem. Here is my working tree: . ├── jest.config.ts ├── package-lock.json ├── package.json ├── spack.config.js └── src ├── components │ ├── FiltersBar │ │ ├── FiltersBar.test.tsx │ │ ├── FiltersBar.tsx │ │ ├── __snapshots__ │ │ │ └── FiltersBar.test.tsx.snap │ │ └── index.ts │ └── index.ts ├── index.ts └── libraries ├── helpers │ ├── helpers.test.ts │ ├── helpers.ts │ └── index.ts └── index.ts Here is my .swcrc file: { "jsc": { "target": "es2021", "parser": { "syntax": "typescript" } }, "module": { "type": "commonjs" } } I'm pretty new to all this stuff so please bear with me :)
Webpack config to generate bundles of two different React SPAs
I have a project with the following structure: . ├── app │ ├── icon.svg │ ├── index.html │ └── scripts ├── config │ └── iparams.json ├── jest.config.js ├── manifest.json ├── __mocks__ │ └── svgrMock.js ├── package.json ├── public │ ├── index.html │ └── iparams.html ├── setUpTests.js ├── src │ ├── App.css │ ├── app.index.css │ ├── app.index.js │ ├── App.js │ ├── App.test.js │ ├── assets │ ├── components │ ├── Config.css │ ├── config.index.css │ ├── config.index.js │ ├── Config.js │ ├── hooks │ ├── log │ └── logo.svg ├── webpack.config.js └── yarn.lock It have two main SPAs: config and app, so, I need to generate two different bundles respectively to ./config and ./app using webpack. The ./src/config.index.js is the entry point of the config app, witch renders the ./src/Config.js React component to the ./config/iparams.html page (using the ./public/iparams.html template). The same logic holds for the app page. Currently I'm using this webpack config without success: 'use strict'; const HtmlWebPackPlugin = require('html-webpack-plugin'); const { CleanWebpackPlugin } = require('clean-webpack-plugin'); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const CopyWebpackPlugin = require('copy-webpack-plugin'); module.exports = { entry: { '../app/': ['#babel/polyfill', `${process.cwd()}/src/app.index.js`], '../config/': ['#babel/polyfill', `${process.cwd()}/src/config.index.js`] }, output: { globalObject: 'this', path: `${process.cwd()}/dist`, filename: '[name].[contenthash:8].js', chunkFilename: '[name].[contenthash:8].js', publicPath: './scripts', clean: true }, devtool: 'source-map', module: { rules: [{ test: /\.(js|jsx|ts|tsx|test.js)$/, exclude: /node_modules/, use: { loader: 'babel-loader' } }, { test: /\.(css|scss)$/, use: [ 'style-loader', 'css-loader' ] }, { test: /\.(png|jpe?g|gif|svg)$/i, use: [{ loader: 'file-loader', options: { name: '[name][contenthash:8].[ext]', outputPath: '/assets/img', esModule: false } }] }, { test: /\.html$/, use: [{ loader: 'html-loader' }] } ] }, plugins: [ new CleanWebpackPlugin({ dangerouslyAllowCleanPatternsOutsideProject: true, dry: false }), new MiniCssExtractPlugin({ filename: '[name].[contenthash:8].css', chunkFilename: '[name].[contenthash:8].css' }), new HtmlWebPackPlugin({ template: `${process.cwd()}/public/index.html`, filename: `${process.cwd()}/app/index.html` }), new HtmlWebPackPlugin({ template: `${process.cwd()}/public/iparams.html`, filename: `${process.cwd()}/config/iparams.html` }), new CopyWebpackPlugin([ { from: 'dist/**/*', to: '../app' } ]), ], optimization: { moduleIds: 'deterministic', runtimeChunk: 'single', splitChunks: { cacheGroups: { vendor: { test: /[\\/]node_modules[\\/]/, name: 'vendors', priority: -10, chunks: 'all' } } } } }; What is the correct webpack configuration for this use case? Note that I'm using a proprietary sdk which doesn't allow a custom build script, just a custom webpack config, also, the pages outputs must be ./app and ./config.
GulpJS can no longer finds task in list properly (Gulp 4)
My gulp file pretty much looks like this (simplified) function copyAssets () { return src(paths.assets, { base: './' }) .pipe(cache('asset-files')) .pipe(dest(paths.build)) } // Some more task functions const build = parallel(copyAssets, brewCoffee, buildTypescript) module.exports = { build, watch: series(build, watchFiles) } But now when I list it it looks like: [15:29:30] Tasks for ..... [15:29:30] ├─┬ <parallel> [15:29:30] │ └─┬ <parallel> [15:29:30] │ ├── copyAssets [15:29:30] │ ├── brewCoffee [15:29:30] │ └── buildTypescript [15:29:30] └─┬ <series> [15:29:30] └─┬ <series> [15:29:30] ├─┬ <parallel> [15:29:30] │ ├── copyAssets [15:29:30] │ ├── brewCoffee [15:29:30] │ └── buildTypescript [15:29:30] └── watchFiles And running things like gulp build will say that the task does not exist. If I wrap the series / paralel function in an anonymised function I do see it appear in the list (like so) const build = () => parallel(copyAssets, brewCoffee, buildTypescript) module.exports = { build, watch: () => series(build, watchFiles) } But then when running gulp build I'm getting Did you forget to signal async completion? as an error. I know at some point this did work (a number of months ago). But now for some reason it doesn't anymore. If I run gulp --version the output is: CLI version: 2.2.0 Local version: 4.0.0 edit: Hmmm. This seems to work module.exports = { build: () => build(), watch: () => series(build, watchFiles)() } But I doubt that's how I should actually do this stuff.... edit2: No, still broken, it runs now, and waits until completion. And then says the same error as before: The following tasks did not complete: build
When I have used parallel (very briefly) in the past I had to reference it from gulp. E.g. Change: const build = () => parallel(copyAssets, brewCoffee, buildTypescript); to: const build = () => gulp.parallel(copyAssets, brewCoffee, buildTypescript); The same with series here: module.exports = { build, watch: gulp.series(build, watchFiles) }
Try this: var srcPaths = { app: [ 'wwwroot/app/**/*.ts' ], js: [ 'node_modules/core-js/client/shim.min.js', 'node_modules/zone.js/dist/zone.js', 'node_modules/reflect-metadata/Reflect.js', 'node_modules/systemjs/dist/system.src.js', 'node_modules/typescript/lib/typescript.js', 'node_modules/ng2-bootstrap/bundles/ng2-bootstrap.min.js', 'node_modules/moment/moment.js' ], } gulp.task('watch', function () { gulp.watch([srcPaths.app, srcPaths.js], gulp.series('js')); }); It will work fine. Enjoy!
Webpack font not found
I started learning webpack and I have this small project I'll be simplifying the content for brevity, hopefully it wont affect your understanding of the problem. . └── project ├── dist │ ├── fonts │ └── js ├── src │ ├── app │ │ ├── app.js │ │ └── component │ │ ├── component.css │ │ ├── component.directive.js │ │ └── component.html │ └── fontello ├── index.html ├── package.json └── webpack.config.js I'm trying to keep everything inside my component encapsulated so I have: component.directive.js require('../../fontello/css/fontello.css'); require('./component.css'); var angular = require('angular'); ... module.exports = angular.module('directives.component', []) .directive('component', component) .name; app.js var angular = require('angular'); var component = require('./component/component.directive.js'); ... angular.module('app', [component]) and webpack.config.js var webpack = require('webpack'); module.exports = { context: __dirname + '/src', entry: { app: './app/app.js', vendor: ['angular'] }, output: { path: __dirname + '/dist', filename: 'js/app.bundle.js' }, plugins: [ new webpack.optimize.CommonsChunkPlugin("vendor", "js/vendor.bundle.js") ], module: { loaders: [{ test: /\.css$/, loader: 'style-loader!css-loader', exclude: ['./src/fontello'] }, { test: /\.(png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)(\?[a-z0-9=&.]+)?$/, loader: 'file-loader?name=fonts/[name].[ext]' }, { test: /\.html$/, loader: 'raw' }] } }; and I get for woff2/woff/ttf 404 Not Found. GET http://localhost:8080/fonts/fontello.woff2 what am I doing wrong?