I'm sharing some code between environments and in one environment a dependency isn't available - but that code isn't imported into the project and the module uses sideEffects: false
- I'd think I should be able to build the project, but if I'm wrong, what am I misunderstanding about tree-shaking and sideEffects
?
The error I get is like: Result of build attempt: Module not found: Error: Can't resolve 'unused-dep' in '...'
I'll break down the sample code into two parts:
my-project
- the main codebase into which I'm importing a function frommy-module
and building viawebpack
my-module
- a module I've made that I'm trying to import a function from
https://webpack.js.org/guides/tree-shaking/ says that @babel/preset-env
's default behavior can interfere, so I've already addressed that and other points in the documentation. I'm guessing I'm just misunderstanding the limitations?
my-project:
index.js
import { someFunc } from 'my-module'
someFunc();
my-module:
package.json
{
"sideEffects": false,
"name": "my-module",
"version": "1.0.0",
"description": "",
"main": "src/index.js",
"author": "",
"license": "",
"dependencies": {
"unused-dep": "*"
}
}
someFunc.js
const someFunc = () => {}
someOtherFunc.js
import { someDep } from 'unused-dep'
const someOtherFunc = () => {
someDep()
}
index.js
export * from './someFunc'
export * from './someOtherFunc'