Comments (14)
Cool, exports
seems to fix that. I will have another look to make sure nothing else breaks and fix it. Thanks!
from highlight-words.
Alright, this is a bit new and experimental, so let's see. Could you try the beta and see if that solves it for you? Doing the same as well.
npm install [email protected]
from highlight-words.
FYI: https://replit.com/@tricinel/DecimalSociableDegrees
from highlight-words.
Alright, great! 1.1.1 is just out.
from highlight-words.
Live demo (click the Run button at the top):
https://replit.com/@karlhorky/DecimalSociableDegrees#.replit
from highlight-words.
Wonder if the esModuleInterop
option is necessary in tsconfig.json
: https://www.typescriptlang.org/tsconfig#esModuleInterop
And maybe, allowSyntheticDefaultImports
can also be removed:
Enabling
esModuleInterop
will also enableallowSyntheticDefaultImports
.
from highlight-words.
Thanks! I need to take a look at this :)
from highlight-words.
Hmm...so as far as I understand this (and I'm not an expert) is that node ships with support for esm modules going forwards (great). If you set type: module in your own package.json
, then your code is a module and importing non-module will give an error.
As you said, you found a workaround, but it's not the only one.
At the moment, we're generating both esm and commonjs bundles, so the bundler you're using will pick whichever is most appropriate. Both rollup and webpack have support for the "module": "dist/highlight-words.mjs"
field in the package.json
file. So if you run your code through a bundler, it will work just fine.
If you want to use highlight-words inside node and in a module, like you are, then you need to import the correct file. Node itself will look at importing whatever is the main
file declared in the package's package.json
. And at the moment, for highlight-words, that is the commonjs bundle. I won't change it for the time being as that might break a whole array of things for others.
The correct file to load would be, in your case:
import highlightWords from 'highlight-words/dist/highlight-words.mjs';
Then use it naturally. I know this is a bit of a pain and I feel you :( When node announced the esm support, they also promised to keep working on providing a good way to have dual commonjs/esm modules. Their announcement is here.
I hope this clears some things up...Of course, if you find a better workaround or a better build setup that covers both commonjs and esm, I'm all for it :)
from highlight-words.
Ok, so there is no standardized field in package.json
for use with Node ESM without a bundler yet?
I guess adding this import
line to the readme would be good...
from highlight-words.
Also getting an error with that workaround you posted:
Cannot find module 'highlight-words/dist/highlight-words.mjs' or its corresponding type declarations.
from highlight-words.
Btw, for more information, this doesn't seem like it's an issue with any of the other libraries that I'm using (I have a long list of dependencies).
from highlight-words.
Ah, seems like the correct field name is not module
, it's exports
:
from highlight-words.
Confirmed, beta version works, also in our app
from highlight-words.
Great, thanks!
from highlight-words.
Related Issues (10)
- Regular expresion in query param? HOT 11
- Invalid query type HOT 2
- This work with IE browser? HOT 1
- Query words with double spaces HOT 4
- Option to ignore diacritics HOT 1
- Declaration file not found with `Node16` module + moduleResolution HOT 12
- Option Proposal: `maxLength` HOT 9
- Investigate potential performance issues HOT 3
- New Option: `clipByLength` HOT 5
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 highlight-words.