Comments (9)
On reddit, there is this error: https://www.reddit.com/r/typescript/comments/4q09uv/help_webpack_weirdness_require_function_is_used/
According to some comment there, the reason might be that there is module: "umd"
is tsconfig.json
instead of module: "commonjs"
. But I'm not quite familiar with js packages export settings, so I don't know what it actually does and what are the consequences. π€·ββοΈ
from touchsweep.
Hi, @dakur, is it possible to paste your webpack config or at least provide a minimal reproducible example?
from touchsweep.
Hi @scriptex, thank you for your answer. I'm able to reproduce it with this minimal config:
module.exports = {
entry: './index.js',
}
I've also removed .babelrc
β even though there is no babel loader β to be sure that no other lib beside webpack is in effect with some magic. β¨
JS:
import TouchSweep from 'touchsweep';
new TouchSweep(document.getElementById('test'))
from touchsweep.
π€ I was able to reproduce this and to be honest, I am not sure why this happens.
It looks like Webpack doesn't like UMD produced by the TypeScript compiler...
Can you try adding the following to your Webpack config:
module: {
unknownContextCritical: false,
},
Webpack's docs do not say much about this configuration setting, though.
from touchsweep.
Yes, unknownContextCritical: false
does the job, but.. π
The aforementioned reddit thread wasn't helpful? It seems to me that this could be the problem:
You need to tell Typescript to emit CommonJS, not UMD. UMD is doing funky stuff with the require function, passing it as an argument into factory. This means webpack can't look at all usages of the top-level require function and figure out exactly what modules you're loading.
It well corresponds to code in dist/
folder of touchsweep installed into my node_modules/
with v2:
from touchsweep.
Okay, looks like I need to change the way the module is built. I guess I will try Vite or Rollup but I donβt have the time right now.
How critical is your situation? π
from touchsweep.
Not at all, I'll wait. Thank you very much!
from touchsweep.
@dakur I've released a new version (2.0.1) on NPM and on Github.
The new release uses Rollup to build and (according to my tests) fixes the Webpack warning.
Please check and let me know π
Thank you for your contribution!
from touchsweep.
Yes, that works very well now, thank you very much!
from touchsweep.
Related Issues (17)
- CVE-2021-23364 (Medium) detected in browserslist-4.16.3.tgz
- CVE-2021-23343 (Medium) detected in path-parse-1.0.6.tgz
- Dependency Dashboard
- Mouse cursor / Desktop option? HOT 2
- CVE-2021-35065 (High) detected in glob-parent-5.1.2.tgz
- CVE-2021-44906 (High) detected in minimist-1.2.5.tgz
- CVE-2019-10744 (High) detected in lodash-4.17.11.tgz
- CVE-2019-20149 (Medium) detected in multiple libraries
- CVE-2015-9251 (Medium) detected in jquery-1.11.1.min.js, jquery-1.12.4.min.js
- CVE-2019-11358 (Medium) detected in jquery-1.11.1.min.js, jquery-1.12.4.min.js
- WS-2016-0090 (Medium) detected in jquery-1.11.1.min.js, jquery-1.12.4.min.js
- CVE-2020-7608 (Medium) detected in yargs-parser-10.1.0.tgz
- WS-2020-0070 (High) detected in lodash-4.17.15.tgz
- Action Required: Fix Renovate Configuration
- CVE-2021-23337 (High) detected in lodash-4.17.20.tgz
- CVE-2020-28500 (Medium) detected in lodash-4.17.20.tgz
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from touchsweep.