InversifyJS: Many source map warnings from compiler due to missing source files
Expected Behavior
No extra compiler warnings when importing inversify in a Typescript project
Current Behavior
After creating a new React Typescript application, adding inversify and starting in dev mode (npm start
), 53 warnings are generated similar to the following:
WARNING in ./node_modules/inversify/es/syntax/binding_to_syntax.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from '<my-project>\node_modules\inversify\src\syntax\binding_to_syntax.ts' file: Error: ENOENT: no such file or directory, open '<my-project>\node_modules\inversify\src\syntax\binding_to_syntax.ts'
@ ./node_modules/inversify/es/container/container.js 173:0-62 371:15-30
@ ./node_modules/inversify/es/inversify.js 3:0-50 3:0-50
@ ./src/App.tsx 9:0-38 17:26-35
@ ./src/index.tsx 7:0-24 11:33-36
The warning message is accurate - the .js.map
files in the inversify npm package all point to .ts
files under src
, but there is no src folder in the npm package.
Possible Solution
Include the src
folder in the npm package, or remove the source maps .js.map
files from the package.
Steps to Reproduce (for bugs)
npx create-react-app my-app --template typescript
npm install --save inversify inversify-react reflect-metadata
- Follow installation instructions (update tsconfig.json etc.)
- Edit application to use inversify in application:
import { Container } from 'inversify';
npm start
Context
Note that inversify works correctly, there is no problem with the actual behaviour of the application, it is just that using inversify is producing a lot of compiler noise.
Although I have installed inversify-react, I doubt that is relevant to this issue, as the warnings appear after importing from inversify directly.
Your Environment
- Version used:
- inversify: 6.0.1
- inversify-react: 1.0.1
- react-scripts: 5.0.0
- Environment name and version (e.g. Chrome 39, node.js 5.4): node.js 14.17.3,
- Operating System and version (desktop or mobile): Windows 10
- Link to your project: N/A
Stack trace
N/A
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 5
- Comments: 15 (2 by maintainers)
Same with react-scripts 5.0.1 and inversity 6.0.1.
So, you have 2 options:
"sourceMaps"
property from the tsconfig.json. FYI: Maybe you will need to explicitly set it tofalse
, as the default might betrue
, I’m not entirely sure.In the case of my build, there were other libraries with the same problem: All of @antvis libraries, which are all in separate github repos, so it would be a bit laborious to raise a PR for all of them, explain what’s happening and wait for a release. So it was easier to just ignore those warnings.
Even after #1412, I still get warnings. Tried to fix it myself by removing
sourceMaps
from the tsconfig, but I still have many libraries in my dependencies that have the same problem.My workaround:
config-overrides.js
:For all the
react-scripts
users, that do not want to installreact-app-rewired
, you can usepatch-package
to ignore these warnings.Just use this patch-file
patches/react-scripts+5.0.1.patch
:This gets rid of the pesky warnings when starting the local dev server or creating a production build.
Oh yeah, you’re absolutely right @jmfrancois!
https://www.typescriptlang.org/tsconfig#inlineSources
removing sourcemap should not be the way. sourcemap are useful for debugging. An other way to fix is to inline the source code in the map file, there is a tsconfig option for that.
Why not just pushing src folder in the release ?
Edit: ok it has been done and then revert but there are still sourcemap in the release : https://unpkg.com/browse/inversify@6.0.1/lib/
Unfortunately, we have yet to release this fix. In the future we will be able to close this issue when the release is completed.
@dcavanagh Would it be possible to do a patch version release?