I am trying to write a web application to work with with Tumblr api. I have already used npm and installed both globally and in the file itself: browesrify, tumblr and tumblr.js. whenever I upload the file to my server which runs on Netlify I get the error that require is undefined.
/* global $ document console len alert require */
// Authenticate via OAuth
var tumblr = require('tumblr');
Here is my error:
script.js:5 Uncaught ReferenceError: require is not defined
I am aware of the fact that this question has been asked before and I have gone through all instances of these types of questions and none of the solutions have worked for me so perhaps something has been updated in one or more of the frameworks.
Netlify will not have Browserify installed on a global scope in npm, so you should set it up in your local project. You set it up using the global install locally, so it works on your local environment.
Make sure you have your package.json setup correctly and it exists.
Install browserify as a development dependency.
$ npm install browserify --save-dev
Add a build script command to your package.json
"scripts": {
"build": "browserify main.js -o bundle.js"
},
Note Your command should use the correct browserify command.
Use npm run build as your Netlify build command.
Related
Am new to Node and npm in general but I'm pretty sure I've gotten the hang at installing packages locally and whatnot. However, I've been trying to get eslint to work for awhile now and it always fails with the same error message despite trying multiple different test projects. It keeps saying that it cannot find a module 'array.prototype.flatmap' (pic provided below). Node is v18.13.0 and npm is v8.19.3 so I'm up to date. ESLint: ^8.31.0.
My steps are (after using 'npm init' to create a package.json file):
1. Locally install eslint to project directory using 'npm init #eslint/config' as shown on the site. (I also tried 'npm install -D eslint' AND THEN 'npm init #eslint/config' to configure after installing.
2. [Configs](https://i.stack.imgur.com/88f4V.png) I have tried with both standard and airbnb configs.
3. Have looked up vids that said to add a script to package.json: "scripts": { "lint": "eslint ./" } and running 'npm run lint'. This results in an error.
4. Have tried running npx eslint 'filename.js' .... same error.
This is the error I keep getting: Error msg:
Have tried repeatedly uninstalling packages, reinstalling, different directories and different projects. Even tried other stackoverflow responses to similar issues with different modules, but no avail. The module that always gives me a problem seems to be 'array.prototype.flatmap'.
Not sure where to from this point. Although I do not NEED eslint and might not use it all the time in the future, I don't want to give up trying simply because I'm having installation issues.
I had the same problem. I found this comment and bumped eslint-plugin-import lib.
// package.json
"eslint-plugin-import": "^2.27.2",
After installing node-crawler in Node.js (not in the default directory) via the npm command, I tried to run the code in the "Usage" section but an error occurs when executing var Crawler = require("crawler"); and the VisualStudio Code debug console says Cannot find module 'crawler'.
Does it happen because I installed crawler in a custom location? How can I fix this?
npm install will install a package locally. (--save to have package appear in your dependencies.)
To have access to it from everywhere, you need to install it globally, using npm install -g
Maybe I found the solution. I replaced "crawler" in var Crawler = require("crawler"); with the path that points to the crawler.js file in the lib folder in node-modules, and now the code works. Maybe it happened because I installed crawler in a custom location and so VisualStudio couldn't find "crawler".
I'm quite new to the whole NPM-stuff, however, I would like to create a new package that should be able to run as a console-app (like gulp and grunt).
So basically what I would like to do is making it possible to run
npm install -g mypackage
and then
mypackage
and that would then kick off the console application.
I have been using npm init to init my new package, I have also created the entry point (in my case app.js), and node app.js runs fine.
I have also used npm pack to create a package and npm install {path to my .tgz}.
This is my app.js:
console.log('Hi from NodeJS');
Nothing fancy so far.
The package is called "mypackage"
The problem is that when I type:
mypackage in my console the console application doesn't run.
Any ideas?
Br,
Inx
You're looking for bin.
To install one or more executable files to PATH, you shoul supply a
bin field in your package.json which is a map of command name to
local file name. On install, npm will symlink that file into
prefix/bin for global installs, or ./node_modules/.bin/ for local
installs.
For example, grunt-cli has this:
"bin": {
"grunt": "bin/grunt"
},
Where bin/grunt is a js file (yet without an extension defined).
P.S. If you're planning to ship this as a global package, don't forget to set preferGlobal.
I am using Node.js for a project. I installed WebdriverIO globally using
npm install -g webdriverio
In one of my files, I have:
file.js
var webdriverio = require('webdriverio');
When this file gets loaded, I get an error in the console that says:
Message:
Cannot find module 'webdriverio'
Details:
code: MODULE_NOT_FOUND
If I comment out the line var webdriverio = ..., my code runs fine.
Considering I've installed webdriverio globally, I do not understand why I'm getting this problem.
When you install globally, you should then go to the root of your app and call:
npm link webdriverio
P.S. no need to call npm install, since you will end up having two separate installations of this module, one in global and another in your local node_modules folder
Node.js require looks into the local node_modules folder.
Check this link to learn how to load modules from the global modules folder:
https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders
If the NODE_PATH environment variable is set to a colon-delimited list
of absolute paths, then node will search those paths for modules if
they are not found elsewhere. (Note: On Windows, NODE_PATH is
delimited by semicolons instead of colons.)
You need it locally for your app, run npm install webdriverio in the root directory of your app.
Node looks for modules in the innode_modules folders only (starting with current folder and then looking in the folder above). In order to make it work, you have to install this package locally as well.
npm install webdriverio
You can use the full global path:
const wdio = require('/usr/local/lib/node_modules/webdriverio');
I have installed Meteorite on my mac, and am trying to run the test program provided as a mysql project. When I use the command 'mrt', I get:
Stand back while Meteorite does its thing
Done installing smart packages
Ok, everything's ready. Here comes Meteor!
[[[[[ /Users/lfrey/Desktop/Thesis/test-meteor-sql ]]]]]
=> Errors prevented startup:
While building the application:
node_modules/meteor/app/lib/unsupported.html:1: Can't set DOCTYPE here. (Meteor sets for you)
node_modules/meteor/app/meteor/meteor.js:1:15: Unexpected token ILLEGAL
=> Your application has errors. Waiting for file change.
I have tried re-installing nom, meteor, meteorite, and mysql in various combinations and have not been able to eliminate the error. If I remove the command, then I get an error about invalid HTML syntax.
Your app might not be created properly. You have a node_modules directory in your application which you might have added with npm install.
Meteor does not install modules with npm install manually, it doesn't work because it parses files in the node_moules directory as part of your meteor app (in the wrong way - not as an npm module).
You have to make sure the package you use uses Npm.depends in your package's package.js. The standard Meteor-SQL package already does this for you so you don't have to worry about it.
Which SQL package did you use? As far as I can see none of them install anything with npm install nor do they have instructions to.
The simple fix to get your app working is to remove the modules you installed by deleting the node_modules directory in your app.