How use openlayers3 in vuejs? - node.js

Through npm install openlayers(4.1.1), I can use openlayers normally in vuejs, but our company custom something base openlayers3.x, so how can I user this custom openlayers? I improt this ol's lib directly, when uses
goog.require("ol.Map")
it reports
goog undefined error!
so, is there any approach to use the custom ol in vuejs? thix.

You can install particular version of openlayers, by mentioning specific version in package.json, like following:
"dependencies": {
"openlayers": "3.x.x"
},
After that you remove earlier installed package and do npm install in the code directory, which will install the correct version you need.

Related

Cannot update the AWS-SDK package in node.js

To this make easier I created a fresh node.js application on VS code. The only package/dependency I install is AWS-SDK. in my package.json the version is shown as "aws-sdk": "^2.1314.0",
as far as I am aware the most recent version is 3.270.0. my node.js version is v14.18.1.
I have manually edited pakage.json to reflect the new version then done npm install aws-sdk again, doesnt work. sometimes it reverts back to 2.1314.0, sometimes the version I added remains but npm aws-sdk list command still shows old version
Hope this is enough information! Thanks
First of all stop using version 2 of aws sdk as it is planned to go into maintenance mode from 2023
Second from version 3, you only use you load and use only the individual AWS Services you need to save the the size of code.
if you need to use only a few AWS services, it means increasing the size of your application with code you don't need or use.
For example to use fynamodb package in version 3 you will use use
npm i #aws-sdk/client-s3
Coming to your question
delete node modules directory
npm cache clean --force
just simple remove the entry in your package.json and add entry like this
"dependencies": {
"#aws-sdk/client-s3": "^3.256.0"
}
npm i #aws-sdk/client-s3
For reference on aws sdk v3 - https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/welcome.html

How to dynamically install a particular version of a NPM package based on local Node.js version?

I did Google about this but no luck.
Basically, I need a particular version of a NPM package (A) to be installed if the local Node.js version is X, if not then install version B of that NPM package. This needs to be a part of build process, so its all dynamic.
If there was a way to have this config in package.json, then it would have been a straightforward solution for me.
How do I achieve this?
You can achieve this by using Yarn as your dependency management tool in combination with the Selective Versions Resolutions feature.
More specifically in your case you'd use it as described in the "Mapping version specifications" format, based on that your package.json you would include something like the following, assuming that version X=1.0.3 and version B=2.0.0 in the following example:
"devDependencies": {
"a": "1.0.3"
},
"resolutions": {
"a#==1.0.3": "a#2.0.0"
}

Yeoman generator composeWith

I am building a generator which uses another sub-generator, using composeWith.
I installed my generator using npm install -g generator-my-generator. When running the generator complains that I do not have my sub-generator installed.
My problem is that I don't want to install the sub-generator globally. I tried using it as a dependency / peerDependency (as suggested here), but it did not help.
Is it possible?
You need to provide the path in composeWith third argument:
this.composeWith('generator:name', {}, {
local: require.resolve('generator-foo/generators/name')
});
require.resolve is usually your best bet, but some generators (like generator-node) provide all the paths inside the main module so you don't have to know the package structure.

Do all npm packages need an export?

I am new to nodejs packages and what I understood was that to share code you had to do a module.export (in addition to adding a package.json)
For example bootstrap-select does not have an export function but is available on npm.
So my question is do all modules require an export and also can I do a require('bootstrap-select') in my code?
no, all npm modules do not require an export. npm is now being used more generally for not only javascript packages intended for use under node.js but front end code for browsers, CSS libraries, etc. At the very least, an npm package could just deliver a payload of files not even including any javascript, such as some images, some CSS, some HTML, etc.
So you can only do require('some-module') if that package has either an index.js file or has set the main property in it's package.json file properly.
However if you are authoring a javascript module for node.js, then yes you'll need to export something in order for your module to load properly.
No, npm modules do not require doing something with module.exports. If you do not touch that object, requireing your module will return an empty object (since that is the default for module.exports. However, this can be useful if your module is only intended to be required for side effects, rather than a return value.
For example, the module you linked to modifies global state by attaching a jQuery event handler.
As per i know ,
1.All npm modules are not required to build an app.
2.If we use var bootStrap = require('bootstrap-select'); using bootStrap variable you can access bootStrap module.
so we can pass that object in anywhere of your code
3.To install a dependency modules,
In package.json give dependency block as like this
"dependencies": {
"express": "2.3.12",
"jade": "latest",
"redis": "0.6.0"
}
you can change and edit your packages. then enter a command npm install in command prompt it will install only dependency modules.
If i made any mistakes please correct me Thanks.

Using localForage and angular-localForage with Browserify causing errors with require statements

I am attempting to install localForage into a node.js application (with Angular) and Browserify.
Here is a link to the localForage documentation
It appears that using localForage and angular-localForage causes a problem with browserify based around the use of 'require'
If I require the localforage.js file in the src file I get the following error:
Warning: module "promise" not found from "/Users/mgayhart/Sites/epson- receipts/bower_components/localforage/src/localforage.js" Use --force to continue.
If I require the localforage.js file in the dist file, I get the following error:
Warning: module "./drivers/indexeddb" not found from "/Users/mgayhart/Sites/epson- receipts/bower_components/localforage/dist/localforage.js" Use --force to continue.
Anyone know of a workaround to be able to move forward with these libraries?
There is an issue on github with this problem: https://github.com/ocombe/angular-localForage/issues/26
I'll be working on it soon, you can subscribe to the github notifs on this issue to know when it's fixed !
For me installing it through bower and using it with browserify-shim worked. So in package.json:
"browser": {
"localforage":"./src/lib/vendor/localforage/dist/localforage.min.js"
},
"browserify-shim": {
"localforage":"localforage"
}
And to expose it as an angular-service (if you don't want to use angular-localforage):
app.factory "localforage",-> require 'localforage'
I've just been having this issue myself tonight, but I think I found a fix.
Instead of trying to get the bower modules to work with browserify, why not just use npm like its made for?
npm install localforage
and then when you use require you don't have to give it the path
but it still didn't work for me until I copied the folder:
localforage/src/drivers TO localforage/dist/drivers
Then it found all the dependencies and worked like a champ!
Alternatively if you must use bower you could try to use the debowerify tranform w/ gulp:
https://github.com/eugeneware/debowerify

Resources