When using webpack and libraries that want to use when.js (when), it is possible that the following error is thrown when compiling:
[2] ERROR in ./node_modules/when/lib/env.js 32:14-35
[2] Module not found: Error: Can't resolve 'vertx' in 'path-to-project/node_modules/when/lib'
The issue seems to be isolated to webpack, and is documented on when's github. Running npm install vertx or npm install #vertx/core will not resolve the issue either, since the problem lays in the import of vertx in the when library.
To resolve the issue:
Install #vertx/core (npm i #vertx/core)
Edit the file ./node_modules/when/lib/env.js, and change line 32 from
var vertx = vertxRequire('vertx');
to
var vertx = vertxRequire('#vertx/core');
This will reference the #vertx/core package instead of the vertx package, which does not seem to be able to be found when using webpack and npm. I haven't experienced any issues with just using vertx/core. You might also need to update your gitignore to include the changes to the library if others are also working on your project.
The issue can indeed be solved by adding the #vertex/core package, but instead of editing the ./node_modules/when/lib/env.js file manually as recommended by #Todd Rylaarsdam, I'd use the NormalModuleReplacementPlugin in your Webpack config to replace the old vertx package, like so:
new webpack.NormalModuleReplacementPlugin(
/^vertx/,
'#vertx/core',
)
This way you don't have to make any manual changes to the files of a package you're using.
See https://webpack.js.org/plugins/normal-module-replacement-plugin/ for more info about this plugin.
Related
Trying to compile a project and being greeted with
Compiling your contracts...
===========================
> Compiling .\src\contracts\TokenFarm.sol
> Artifacts written to C:\Users\sean\AppData\Local\Temp\test--17472-6fYHF170F1H9
> Compiled successfully using:
- solc: 0.5.16+commit.9c3226ce.Emscripten.clang
Error: Cannot find module 'react-bootstrap/lib/Breadcrumb'
Require stack:
I've tried manually installing the package with
npm install --save Breadcrumbs
But I can't seem to find the correct link to download the library
Is there a way to install an older version of node because I believe the repo I'm cloning from is from a few years ago so there could be some dependency issues going on.
You don't need to downgrade your node version. It appears your react-bootstrap has been updated with a major release, without updating related references.
To fix this, either downgrade your library version as suggested by Drew Reese, or just fix your imports.
If you look over the library codebase, you can see you should now import your components through react-bootstrap/src/Breadcrumb instead.
This question already has answers here:
SyntaxError: Cannot use import statement outside a module
(34 answers)
Closed last year.
I'm trying to import myArr from hello.js into index.js. However I get an error of
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module
File hello.js
export let myArr = ['hello', 'hi', 'hey'];
File index.js
import { myArr } from './hello.js';
console.log(myArr);
Where am I going wrong?
Use version 2:
npm install node-fetch#2
node-fetch from v3 is an ESM-only module - you are not able to import it with require().
If you cannot switch to ESM, please use v2 which remains compatible with CommonJS. Critical bug fixes will continue to be published for v2.
I ran your code without any problems. Check for two things:
Node.js version >= 14. It only works with the latest version of Node.js.
Make sure your package.json includes a line for "type": "module". Without this line, Node.js assumes you want to use CommonJS modules rather than ESM.
I ran into a similar issue while building my React project.
Here's the error:
ERROR in ./src/index.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/pradeep/Work/my_project/node_modules/#babel/runtime/helpers/interopRequireWildcard/_index.mjs
Then I realized that I am on a different Node.js version than the one used to install packages in this project.
I had two options:
Change Node.js version to the one required by this project and build again.
Stay on the Node.js version you have and remove the node_modules directory and package-lock.json file and do npm install again.
I chose the first approach and it worked for me.
If you have Node.js version lower than 14, e.g., v12 - you must specify this flag:
node --experimental-modules your.mjs
I use nvm to install the latest stable version of Node.js.
To delete the package-lock.json file and the node_modules folder, run npm. I then npm start to solve my problem.
Rename hello.js to hello.mjs.
You are using CommonJS right now with the .js extension. To import ES6 modules, you will have to change the extension of the file that you want to import to .mjs so it knows that it is an ES6 module.
The problem is that Node.js does not currently support import and export natively yet. It is still experimental according to the documentation. I recommend you use Babel to compile your code and allow you to use import and export.
For example, you can install the #babel/node package and run your project using:
npx babel-node index.js
Here are the documentation for #babel/node. Like the documentation state, this command is only meant for local development. In production, they recommend a configuration like this.
When I am trying to create a vue project using the vue-cli it is giving me the following error message.
ETARGET
No matching version found for #babel/plugin-transform-object-super#^7.8.3.
In most cases you or one of your dependencies are requesting a package version that doesn't exist.
It was specified as a dependency of '#babel/preset-env'
A complete log of this run can be found in: /home/avinash/.npm/_logs/2020-01-13T23_53_01_890Z-debug.log
my node version is v12.14.1
npm version is v6.13.4
I was facing this issue a while ago and this is what worked for me:
Are you perhaps using your company laptop where your npm registry is not set by default to: https://registry.npmjs.org/ ?
If yes, you may go to your .npmrc file, comment out your current registry, and set registry = https://registry.npmjs.org/
Run your vue-cli command, and then restore the .npmrc to original settings :)
Not sure if you have a similar issue but this is what worked for me.
I have recently installed intellij idea on my PC and started react-native application. I installed all libraries required for react native and react js. Also installed node js module and all plugins for this ide. Still i am getting error below like this in import statement.
When i move to that line that shows me error like.
-> Install TypeScript definition for better type information.
But my typeScript definition are also as per required.
Also I have changed my JS to ReactJSX.
I have attached image over here for reference.
You should try to create a new project using following commands
npm install -g create-react-app
create-react-app my-app
cd my-app
npm start
If you still facing error then try to use vscode editor and select react language. If you still face issue let me know
I'm trying to use a npm package from Meteor.js (Release 0.6.6.3) using Meteor.require. However it throws an error saying that require is not defined. Why is this and how can we solve it?
mrt add npm
npm install github
packages.json
{
"github": "0.1.8"
}
github.js
var GITHUB = Meteor.require('github');
Error
ReferenceError: require is not defined
The npm package has lines such as
var https = require('https')
var url = require('url')
var crypto = require('crypto')
Must the package's code be manually edited to use Npm.require? Editing them manually got rid of the errors.
However theres a line:
module.exports = SOMETHING
How should we call module from within meteor?
Meteor.require is a function added by the meteor npm smart package, which actually doesn't do much for using npm other than wrapping some asynchronous callbacks. It's a few months old, so you might want to try using Meteor's Npm.require directly in case something broke.
The monkey-patching of the Meteor global by this package is misleading.
Making comments above an answer.
Is Meteor.require() a typo? That is what is in your code though your question text refers to the correct Npm.require().
I think module.exports is there for non-meteor use of the same file. Within meteor variables for export should be
declared as globals inside the package
exported with api.export() within the package.js file.
The documentation on this is a bit rough but look at namespacing and writing packages. Also looking into the various meteor packages on github is very useful.
Use Npm.require() in meteor.
Like this:
var fs = Npm.require("fs");
For that you need to have a Meteor package: meteorhacks:npm , npm-container
Make sure you're using the meteor-npm package.
https://www.npmjs.com/package/meteor-npm