How to install npm module from local folder? - javascript

I downloaded a package from github: list.fuzzysearch.js. Unzipped it to a folder
Then in my project folder, I install it as follows:
npm install Path/to/LocalFolder/list.fuzzysearch.js-master -S
When I bundle my project js using webpack, I got below error, which seems to miss some module required by the package I installed.
Question 1: Should I do a npm install in the downloaded package's folder first, before I install this package into my project. i.e: ~/local/folder/list.fuzzysearch.js-master$ npm install
Question 2: when I import a module in my app.js, how do I write the path? i.e. import module frommodulePath, thatmodulePath`, shall I just put module name (e.g. 'react'), or the path to the js file in node_module folder (e.g. 'node_module/react/dist/react.js') ?
Question 3: is there a way to find out all transitive dependency of a module, and install them along the way?
errors:
ERROR in ./~/list.fuzzysearch.js/index.js
Module not found: Error: Cannot resolve module 'classes' in /home/mypc/IdeaProject/OpenDimSum/frontend/node_modules/list.fuzzysearch.js
# ./~/list.fuzzysearch.js/index.js 1:14-32
ERROR in ./~/list.fuzzysearch.js/index.js
Module not found: Error: Cannot resolve module 'extend' in /home/mypc/IdeaProject/OpenDimSum/frontend/node_modules/list.fuzzysearch.js
# ./~/list.fuzzysearch.js/index.js 3:13-30
ERROR in ./~/list.fuzzysearch.js/index.js
Module not found: Error: Cannot resolve module 'to-string' in /home/mypc/IdeaProject/OpenDimSum/frontend/node_modules/list.fuzzysearch.js
# ./~/list.fuzzysearch.js/index.js 4:15-35
ERROR in ./~/list.fuzzysearch.js/index.js
Module not found: Error: Cannot resolve module 'get-by-class' in /home/mypc/IdeaProject/OpenDimSum/frontend/node_modules/list.fuzzysearch.js
# ./~/list.fuzzysearch.js/index.js 5:17-40
my app javascript:
require('../../../node_modules/bootstrap/dist/css/bootstrap.css')
require ('../public/styles.css')
require ('../index.html')
import React from 'react'
import {render} from 'react-dom'
import 'list.js'
import 'list.fuzzysearch.js'
require('../../../node_modules/bootstrap/dist/js/bootstrap')

Looks like the script you want to use is an npm package, even though it isn't published to the npm registry. This is how you can add it to your project:
Add "list.fuzzysearch": "javve/list.fuzzysearch.js" under dependencies in your package.json
npm install as usual
import fuzzysearch from 'list.fuzzysearch'
???
PROFIT!!!
The npm client is really flexible when it comes to where a package can be installed from. Here's the relevant documentation.

Related

Module not found: Error: Can't resolve 'vue-confirm-dialog'

Vue.js + node.js is the basis of my app. I wanted to use the vue-confirm-dialog package from npm but this code line leads to an error:
import VueConfirmDialog from 'vue-confirm-dialog'
I have already executed: npm install --save vue-confirm-dialog and the module vue-confirm-dialog appears in the package.json file.
The error message Module not found: Error: Can't resolve 'vue-confirm-dialog' still appears.
Had the same issue today, solved it by downgrading vue-confirm-dialog to 1.0.2.
npm install vue-confirm-dialog#1.0.2 --save

Angular custom npm package 'Cannot find module'

I have created a custom npm package library, I have successfully created it and published on npm and then installed the package using npm install <my-package-name>.
And now I am facing issue on importing the package.When I import it in app.module.ts file its shows:
Cannot find module 'my-module-name' or its corresponding type declarations.
I have also tried by deleting the node-modules and package-lock.json files and then npm install but sadly it's not works.

Could not find a declaration file for module 'react'

I learn Microsoft's manual about TypeScript + React + Redux.
I launched the command:
npm install -S redux react-redux #types/react-redux
But when I run the command npm run start I get the error:
Type error: Could not find a declaration file for module 'react'.
'C:/lab/my-app/node_modules/react/index.js' implicitly has an 'any'
type.
Ok, I run the command: npm i #types/react. now I get other error:
Type error: Module '"../../node_modules/#types/react-redux"' has no
exported member 'Dispatch'. TS2305
How can I fix it?
I had this problem when I initially created a React with TypeScript project, it made no sense since I had not started any work yet.
So in terminal I ran:
rm -rf node_modules/ && npm install
Then:
npm run start
And I was able to see the main landing page.
run the following:
pm install #types/react
It works for me!

Installing dygraphs with bower install fails on Ember.js

Issuing a statement:
bower install dygraphs --save
And than adding reference to dygraphs:
app.import('vendor/dygraphs/src/dygraph.js')
Causes an error:
Uncaught SyntaxError: Unexpected identifier
on line:
import DygraphLayout from './dygraph-layout';
And:
Uncaught ReferenceError: define is not defined
at ember-adater-file.js:1
What can be the cause of this and how to fix it?
You are trying to app.import an ES6 module, which is not supported.
Since Ember is discouraging the use of bower, you can try installing dygraphs through npm
npm install --save-dev dygraphs
And use ember-browserify to import it.
npm install --save-dev ember-browserify
Then in your code you can do
import Dygraph from "npm:dygraph";
And use it right away in your component.

including npm module in google cloud functions

I am trying to include local npm package in a cloud function. I used the following commands:
$ npm pack
$ npm install --save tarball-output.tgz
How do I include a packed npm package in app.js? I used:
let mypackage = require('my_package');
I getting the following error when trying to deploy:
ERROR: (gcloud.beta.functions.deploy) OperationError: code=3,
message=Function load error: Code in file app.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'my_package'
Your package.json must point to your tarball, like this:
{
"dependencies": {
"my_package": "file:tarball-output.tgz"
}
}

Categories