All Questions
59 questions
0
votes
0
answers
21
views
Rollup.js ES bundle failing to resolve react-icons/io5 dependency
I'm working on creating an NPM package (for a private company-specific NPM registry) containing a single React component and from searching online on how to do this, I decided to use Rollup.js to ...
2
votes
0
answers
196
views
How do you combine subpath exports, environment conditional exports, and module system conditional exports in the same package.json?
When publishing an NPM package, there are three distinct types of export that you can specify in a package.json file.
Subpath Exports
This allows you to export multiple ‘indexes’ from a single ...
0
votes
0
answers
1k
views
NPM test script fails with "Error [ERR_REQUIRE_ESM]"
I'm trying to update dependencies for my React Node project, and any update to package.json at all, including deleting yarn.lock and installing the same dependencies fresh with yarn, causes yarn test (...
1
vote
1
answer
357
views
As CommonJS dies out, what should go in a library’s package.json "main" field?
When the maintainer of a JavaScript package decides to stop distributing a CommonJS version, what should go into the "main" field of the package.json file?
Example old package.json fields ...
0
votes
0
answers
23
views
React module system vs Express module system
When using react, we import the library in the following manner
import React from 'react'
In express, we use
const app = require('express')
In their github source code, both of them uses module....
2
votes
0
answers
186
views
NPM package with exports won't load in typescript
Our library needs to work both for projects using ESM modules and CommonJS. Therefore we built it with 3 different configurations: ESM, node16, and types.
This setup works for JavaScript projects with ...
-1
votes
1
answer
279
views
Does Windows' VS Code recognize tilde (~) character when requiring modules?
I am developing from a source code that was created using a UNIX-based system. I am using Windows-based system and there are a lot of modules required using the tilde character. Somehow, my VS Code ...
5
votes
1
answer
215
views
How to import the same npm module in more than one TypeScript file? [duplicate]
Question:
Whenever I import the same npm module in more than 1 TypeScript file, I got the error "error TS2451: Cannot redeclare block-scoped variable 'os'" as soon as I run the TypeScript ...
2
votes
2
answers
899
views
"does not contain a default export" even though one is declared
Software rots. I made a minor change to a three year-old GitHub project and the rebuild failed due to automatic security patches. Got everything fixed except for a default import failure.
The error is:...
0
votes
1
answer
296
views
Axios response is raw in npm package
So I have been trying to publish a npm package.
Requisites:-
CommonJs.
Axios (I can change this if you have better options)
typescript
So the server response in json when I wrote the code, but when ...
1
vote
0
answers
1k
views
Node.js: How to use npm ES6 modules (import) in commonjs (require) app.js
I'm kind of a newbie with node.js, so please, be merciful :)
I use node ver 14.15.1
The problem I'm facing is to get a npm module("ghost-cursor", https://www.npmjs.com/package/ghost-cursor) ...
2
votes
2
answers
1k
views
How do I require a function in a node modules without using a Module Bundler
I cannot find an accurate answer to this anywhere. I understand the browser doesn't recognise commonJS syntax hence why if require() is loaded into the browser a reference error occurs like this
let ...
0
votes
1
answer
813
views
Include a few ES style npm modules into a project with mostly commonJS modules
I have browsed a lot of questions in this space, but I haven't found a clear answer.
I recently updated many of my project's npm dependencies to their latest. The project is entirely built around ...
0
votes
1
answer
881
views
How to my npm package in a way such that people can load it from JSDelivr?
I'm writing an NPM package in typescript for learning purposes. I configured my parcel set up so it exports two kinds of builds, an ESM build and a CJS one. I published it to npm and I can install and ...
0
votes
1
answer
1k
views
Best practice for NPM package with es6 modules - bundle or not
Writing an NPM package containing es6 modules, is it best practice to keep the source files separate
package.json
esm
index.js
Content1
Content1A.js
Content1A.js.map
Content1B.js
Content1B....
0
votes
1
answer
496
views
karma-typescript confused by .d.ts typings into failing to bind to npm package code
I'm importing an npm package into my project with a package.json like this:
{
// ...
"browser": "dist/umd/index.js",
"main": "dist/cjs/index.js",
"...
0
votes
1
answer
864
views
bundle an npm package AND convert it into an es module
I want to import chessground into a project of mine. It seems it's a CommonJS module, so i used browserify to import it into my web page.
browserify -r chessground > chessground.js
In order to use ...
0
votes
1
answer
390
views
How can I use an npm package that just wraps my JavaScript code?
We currently have an npm package for clients to use on their ES6-based projects like React. This main index file of this package has the following shape:
export function ourFunction() {
}
And ...
6
votes
0
answers
1k
views
Typescript library for Node as hybrid package in NPM
How to properly configure typescript tsconfig.json and npm package.json to create a hybrid npm package?
I mostly followed this article (but I also tried other methods)
This is the alpha version of my ...
5
votes
1
answer
6k
views
cjs or esm for react components library [closed]
I got a components library that will be published to npm to be consumed by a razzle app. My main question that I want opinions on best practices is, should the packages be built with cjs or esm, and ...
2
votes
1
answer
2k
views
How to publish dual npm package (CommonJS + modules) so that submodules are uniformly imported
I have been struggling with packaging an NPM package so that it bundles both CommonJS and ES modules but either are imported with the same absolute module path. Not only the main module.
For example, ...
2
votes
0
answers
156
views
How (or maybe whether) to put both es6 style and csj style files in an NPM module I am publishing
I am going to publish an NPM module but I need clarification on how/whether to put both ES6 import/export style and Node CommonJS require style in the published directory.
According to one website I ...
2
votes
1
answer
1k
views
Uncaught ReferenceError: require is not defined Webpack + AngularJS
There's dozens and dozens of questions like this one, and none have helped because the root cause is always something I'm not doing. I'm making a bundle for the browser with webpack 4.26.1, and I keep ...
1
vote
1
answer
882
views
Typescript: Compile ambient module declarations for publishing to NPM
I am looking for suggestions to automatically have TypeScript compile node (commonjs) ambient module declarations for a npm package I am currently writing in TypeScript. I seem to be running into some ...
1
vote
0
answers
169
views
Import fails with file outside the root folder - webpack
If I place a .js file outside the root folder where package.json is, and then I try to import it, it fails.
I can run npx webpack which seems to run without problems, but then the application fails ...
2
votes
1
answer
2k
views
Converting Typescript absolute paths to nodejs relative paths?
I'm compiling typescript to es5 / commonjs format. I'm using typescript's tsconfig.json paths property to specify a fixed root for `import statements.
So for example I might have a path ...
41
votes
1
answer
22k
views
How are UMD and CommonJS (CJS) package folders different, and which should I use?
I installed reactjs and react-dom like this with package.json
"dependencies": {
"bootstrap": "^v4.1.1",
"popper.js": "^1.14.3",
...
0
votes
1
answer
508
views
Publishing both es6 and commonjs with subfolders
I want to be able to import module from subfolder like this, without any lib folder, https://davidwells.io/blog/publishing-flat-npm-packages-for-easier-import-paths-smaller-consumer-bundle-sizes/
I ...
4
votes
1
answer
335
views
How to publish a component written in typescript consumable as a global, commonjs, or typescript module
I have written a simple component in typescript which has a dependency on d3. I would like to publish this component on npm and have it be usable as a global, a commonjs module, or a typescript module....
3
votes
0
answers
316
views
Browserify - Uncaught Error: Cannot find module 'undefined'
In my final bundle.js file which includes all js modules, I'm getting the following error
Uncaught Error: Cannot find module 'undefined'
at s (bundle.js:1)
at bundle.js:1
at Object.33.../Utility (...
7
votes
2
answers
706
views
Indirectly reference remote Javascript URL
We want to use Rollup with Angular 4/Typescript and NPM
We have the following requirement within our company:
Certain teams create JS libraries which need to be centralized (like a CDN)
These ...
4
votes
0
answers
568
views
Include static data files in an NPM package, use them in a portable way
I want to publish an NPM package that contains a large-ish amount of static data files. There could be 1000 files, containing 1 KB of data each, yielding 1 MB or so of data. It is important that that ...
375
votes
48
answers
595k
views
Field 'browser' doesn't contain a valid alias configuration
I've started using webpack2 (to be precise, v2.3.2) and after re-creating my config I keep running into an issue I can't seem to solve I get (sorry in advance for ugly dump):
ERROR in ./src/main.js
...
8
votes
5
answers
851
views
Which npm packages will and will not work on Angular 2? How do I tell?
Does an NPM package need to be modified to be compatible with Angular 2 (eg. add in typings, make directives for them) or will any existing package work? If they're not all compatible, how do I know ...
0
votes
1
answer
110
views
Webpack and ts-loader bundle returning TypeError on third party library
Everything compiles and bundles however there is a TypeError in the browser: "box2dweb_commonjs_1.default is undefined."
No error on starting webpack-dev-server and checking the bundle at http://...
0
votes
0
answers
223
views
Performance for common.js modules export
How do I export a number modules via an index.js file while making sure they don't impact performance? Probably best explained with a source code:
// index.js
module.exports = {
Database : {
...
0
votes
2
answers
464
views
How to fetch modules from npm as standalone AMD/CommonJS modules
So, I'm not using Node or WebPack serverside, but would still like to use modules from npm every now and then. My clientside uses requirejs, so I would need the modules in either AMD (preferred) or ...
0
votes
0
answers
261
views
I can't link javascript files as commonjs modules
I have:
test.json - contains the content to be uploaded into the HTML page
test.js - contains the function that sends an Ajax request to the JSON file, parses, compiles with Handelbars Temlate and ...
0
votes
1
answer
443
views
Commonjs library's index.ts as external module
I need some guidance to correctly develop reusable commonjs library (npm package).
Lets say the library structure is the following:
—lib
——Helper.ts
——Serialization.ts
——meta
——— Entity.ts
—index.ts
...
0
votes
1
answer
475
views
How to use webpack with js that isn't exported
I'm trying to figure out how to include this javascript with webpack but I'm struggling. I'm installing an angular module called angular-colorthief via npm. I've installed it and included the module ...
1
vote
0
answers
350
views
Highcharts click event not working with npm standalone module
I recently migrated an existing ReactJS component that renders a Highcharts chart into CommonJS format. Accordingly, the Highcharts library is now included via ES6 import, as supposed to via the <...
1
vote
1
answer
159
views
Loading GoCardless SDK with require not working
When I try and load the GoCardless SDK and appy the congfig as sated in the documentation nodejs throws me the following error:
var gocardless = require('gocardless')(gcConfig);
...
0
votes
1
answer
37
views
require('backbone') returns different object in different files
backbone1.js
var backbone1=require('backbone');
window.backbone=backbone1;
backbone2.js
console.log(window.backbone===require('backbone'));
Why is the condition returning false. Shouldn't it ...
4
votes
1
answer
2k
views
Browserify bundle output is very large, cannot find a way to debug the process
I'm using browserify with npm to create a bundle of js. The web app using react and a lot of other modules so the output file is about 3.4M, 2M uglyfied and 430K gzip.
The browserify process is ...
1
vote
1
answer
2k
views
Use class from CommonJS module in Typescript
I have an npm package with a file similar to this:
'use strict'
module.exports = class TModel {
constructor (app) {
this.app = app
}
static schema () {
}
}
Which I want to use in a ...
1
vote
1
answer
271
views
Why npm packages often use relative paths for require (e.g. ../../file)?
A number of packages on npm seem to use require function in the following way:
var CounterActions = require('../actions/counter');
instead of this:
var CounterActions = require('mypackage/actions/...
1
vote
1
answer
446
views
How does lodash's modular build work? Or any commonjs modular build work?
It's my understanding that I can
npm install lodash
but then call
require('lodash/collections/each')
and only get that single function without the overhead of loading all of lodash.
How does ...
0
votes
1
answer
55
views
How do I think and act in Require.js if I have a <script src="..."> background and a Django backend?
I started and stopped asking several questions to help me get (in the immediate need) react-tooltip, which does not advertise a non-CommonJS distribution. But I expect to want to do other things that ...
24
votes
3
answers
12k
views
Webpack doesn't find a module that actually exists
I'm in trouble, I just did npm uninstall react-bootstrap and then npm install react-bootstrap and webpack cannot load this module anymore.
I launch webpack like this :
/var/www/cloud/node_modules/....
1
vote
0
answers
71
views
Browswerify compiling to full paths even when fullPaths is set to false
I have the following gulp task:
var source = require('vinyl-source-stream'),
gulp = require('gulp'),
browserify = require('browserify'),
reactify = require('reactify'),
notify = ...