InversifyJS icon indicating copy to clipboard operation
InversifyJS copied to clipboard

Many source map warnings from compiler due to missing source files

Open pcroc opened this issue 3 years ago • 15 comments

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)

  1. npx create-react-app my-app --template typescript
  2. npm install --save inversify inversify-react reflect-metadata
  3. Follow installation instructions (update tsconfig.json etc.)
  4. Edit application to use inversify in application: import { Container } from 'inversify';
  5. 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

pcroc avatar Dec 17 '21 10:12 pcroc

I'm getting the same error after upgrading to react-scripts@5. @pcroc did you find any workarounds to suppress the warnings?

ianldgs avatar Jan 03 '22 17:01 ianldgs

@ianldgs the only current solution is to use some method (ejecting/forking/some lib) to modify Webpack config to ignore source map warnings.

NaomiGilbertE22 avatar Jan 12 '22 07:01 NaomiGilbertE22

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:

  1. Install https://github.com/timarney/react-app-rewired
  2. Create a config-overrides.js:
module.exports = {
  webpack(config, env) {
    config.ignoreWarnings = [/Failed to parse source map/];
    return config;
  },
};

ianldgs avatar Feb 04 '22 15:02 ianldgs

Even after https://github.com/inversify/InversifyJS/pull/1412, I still get warnings.

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?

jkhmtx avatar Feb 17 '22 02:02 jkhmtx

Even after #1412, I still get warnings.

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?

I used npm v8 overrides and published a clone of the repo to a local npm registry because I was too impatient. Trust me, the PR that was merged doesn't fix the problem.

ianldgs avatar Feb 17 '22 13:02 ianldgs

Thank you for adding that. Truthfully I am naive to this problem and made the assumption that removing the map files from the build artifict would resolve the issue.

It sounds to me like there is a discrepancy in our build that points to the source directory that is present from the repo root, but not present in the build directory. It also sounds like we could be including inline source despite excluding the .map files.

I haven't investigated yet myself, those are just my guesses.

I appreciate that even though you have a workaround and that you have made a deep attempt at exploring the resolution already, you are willing to report back these findings 🙏

I can try to take a look this weekend at what could be happening. Do you have any guesses yourself as to what could be going on?

jkhmtx avatar Feb 17 '22 14:02 jkhmtx

So, you have 2 options:

  1. If you want to publish sourceMaps to give people a better developer experience, you will also have to publish the source code in TypeScript. That is because the sourceMaps (inline or not) will point to the TypeScript files. And if those files don't exist in the node_modules, there will be another error from the source map loader.
  2. Do not generate sourceMaps at all, by removing the "sourceMaps" property from the tsconfig.json. FYI: Maybe you will need to explicitly set it to false, as the default might be true, 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.

ianldgs avatar Feb 17 '22 14:02 ianldgs

I am getting lots of warning too. I am using Vue + Nuxt3

Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/inversify.js" points to missing source files                                                                                                                                                           21:25:04


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/constants/metadata_keys.js" points to missing source files                                                                                                                                             21:25:04


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/container/container.js" points to missing source files                                                                                                                                                 21:25:04


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/bindings/binding.js" points to missing source files                                                                                                                                                    21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/constants/literal_types.js" points to missing source files                                                                                                                                             21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/utils/id.js" points to missing source files                                                                                                                                                            21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/constants/error_msgs.js" points to missing source files                                                                                                                                                21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/planning/metadata_reader.js" points to missing source files                                                                                                                                            21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/planning/planner.js" points to missing source files                                                                                                                                                    21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/bindings/binding_count.js" points to missing source files                                                                                                                                              21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/utils/exceptions.js" points to missing source files                                                                                                                                                    21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/utils/serialization.js" points to missing source files                                                                                                                                                 21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/planning/context.js" points to missing source files                                                                                                                                                    21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/planning/metadata.js" points to missing source files                                                                                                                                                   21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/planning/plan.js" points to missing source files                                                                                                                                                       21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/planning/reflection_utils.js" points to missing source files                                                                                                                                           21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/annotation/lazy_service_identifier.js" points to missing source files                                                                                                                                  21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/planning/target.js" points to missing source files                                                                                                                                                     21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/planning/queryable_string.js" points to missing source files                                                                                                                                           21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/planning/request.js" points to missing source files                                                                                                                                                    21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/resolution/resolver.js" points to missing source files                                                                                                                                                 21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/scope/scope.js" points to missing source files                                                                                                                                                         21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/utils/async.js" points to missing source files                                                                                                                                                         21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/utils/binding_utils.js" points to missing source files                                                                                                                                                 21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/utils/factory_type.js" points to missing source files                                                                                                                                                  21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/resolution/instantiation.js" points to missing source files                                                                                                                                            21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/syntax/binding_to_syntax.js" points to missing source files                                                                                                                                            21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/syntax/binding_in_when_on_syntax.js" points to missing source files                                                                                                                                    21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/syntax/binding_in_syntax.js" points to missing source files                                                                                                                                            21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/syntax/binding_when_on_syntax.js" points to missing source files                                                                                                                                       21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/syntax/binding_on_syntax.js" points to missing source files                                                                                                                                            21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/syntax/binding_when_syntax.js" points to missing source files                                                                                                                                          21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/syntax/constraint_helpers.js" points to missing source files                                                                                                                                           21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/container/container_snapshot.js" points to missing source files                                                                                                                                        21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/container/lookup.js" points to missing source files                                                                                                                                                    21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/utils/clonable.js" points to missing source files                                                                                                                                                      21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/container/module_activation_store.js" points to missing source files                                                                                                                                   21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/container/container_module.js" points to missing source files                                                                                                                                          21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/annotation/decorator_utils.js" points to missing source files                                                                                                                                          21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/utils/js.js" points to missing source files                                                                                                                                                            21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/annotation/injectable.js" points to missing source files                                                                                                                                               21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/annotation/tagged.js" points to missing source files                                                                                                                                                   21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/annotation/named.js" points to missing source files                                                                                                                                                    21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/annotation/inject.js" points to missing source files                                                                                                                                                   21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/annotation/inject_base.js" points to missing source files                                                                                                                                              21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/annotation/optional.js" points to missing source files                                                                                                                                                 21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/annotation/unmanaged.js" points to missing source files                                                                                                                                                21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/annotation/multi_inject.js" points to missing source files                                                                                                                                             21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/annotation/target_name.js" points to missing source files                                                                                                                                              21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/annotation/post_construct.js" points to missing source files                                                                                                                                           21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/annotation/property_event_decorator.js" points to missing source files                                                                                                                                 21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/annotation/pre_destroy.js" points to missing source files                                                                                                                                              21:25:04  


 WARN  Sourcemap for "D:/project/node_modules/.pnpm/[email protected]/node_modules/inversify/es/interfaces/interfaces.js" points to missing source files 

shtse8 avatar Jul 05 '22 13:07 shtse8

Same with react-scripts 5.0.1 and inversity 6.0.1.

artemderiddev avatar Jul 25 '22 12:07 artemderiddev

When will there be a release?Since this is already fixed in the codebase, it is really just need a update in npm.

@remojansen @Jameskmonger @dcavanagh Please!

linonetwo avatar Nov 01 '22 11:11 linonetwo

Any updates on this issue?

Kn3cht avatar Jan 27 '23 14:01 Kn3cht

Maybe we need to ping maintainers on the IM

linonetwo avatar Jan 28 '23 02:01 linonetwo

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/[email protected]/lib/

jmfrancois avatar Feb 07 '23 16:02 jmfrancois

Oh yeah, you're absolutely right @jmfrancois!

https://www.typescriptlang.org/tsconfig#inlineSources

ianldgs avatar Feb 07 '23 17:02 ianldgs

For all the react-scripts users, that do not want to install react-app-rewired, you can use patch-package to ignore these warnings.

Just use this patch-file patches/react-scripts+5.0.1.patch:

diff --git a/node_modules/react-scripts/config/webpack.config.js b/node_modules/react-scripts/config/webpack.config.js
index e465d8e..26ad0fa 100644
--- a/node_modules/react-scripts/config/webpack.config.js
+++ b/node_modules/react-scripts/config/webpack.config.js
@@ -792,5 +792,6 @@ module.exports = function (webpackEnv) {
     // Turn off performance processing because we utilize
     // our own hints via the FileSizeReporter
     performance: false,
+    ignoreWarnings: [/Failed to parse source map/],
   };
 };

This gets rid of the pesky warnings when starting the local dev server or creating a production build.

FibreFoX avatar Feb 20 '23 12:02 FibreFoX