guides-source
guides-source copied to clipboard
Proposition: Add note about corner case in documentation related to using commonjs
The proposition to add a tip about corner case related to naming in https://guides.emberjs.com/release/addons-and-dependencies/#toc_commonjs-javascript-modules
I wanted to use web3.js from https://github.com/ChainSafe/web3.js/tree/v1.7.0
so what was needed: const Web3 = require('web3');
and then using this on code
I spent hours thinking what I am doing wrong because I did:
ember install ember-cli-cjs-transform
app.import('node_modules/web3/dist/web3.min.js', {
using: [
{ transformation: 'cjs', as: 'web3' }
]
});
import web3 from 'web3';
and this gave me an error:
"Build Error (Bundler)
webpack returned errors to ember-auto-import"
which I didn't understand what was wrong
In the end, the problem was with the name "web3"
I needed to use something else like e.g.
app.import('node_modules/web3/dist/web3.min.js', {
using: [
{ transformation: 'cjs', as: 'Web3' }
]
});
import Web3 from 'Web3';
So I think adding notes to documentation about being aware of a potential problem of importing this if the name could crash importing would be nice I think.