Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to parse source map from file: Error: ENOENT: no such file or directory #1194

Open
Tracked by #37
doebi opened this issue Jun 13, 2024 · 20 comments
Open
Tracked by #37

Comments

@doebi
Copy link

doebi commented Jun 13, 2024

frontend-1            | Compiling...
frontend-1            | Compiled with warnings.
frontend-1            | 
frontend-1            | Failed to parse source map from '/app/node_modules/parse5/dist/common/doctype.js.map' file: Error: ENOENT: no such file or directory, open '/app/node_modules/parse5/dist/common/doctype.js.map'
frontend-1            | 
frontend-1            | Failed to parse source map from '/app/node_modules/parse5/dist/common/error-codes.js.map' file: Error: ENOENT: no such file or directory, open '/app/node_modules/parse5/dist/common/error-codes.js.map'
frontend-1            | 
frontend-1            | Failed to parse source map from '/app/node_modules/parse5/dist/common/foreign-content.js.map' file: Error: ENOENT: no such file or directory, open '/app/node_modules/parse5/dist/common/foreign-content.js.map'
frontend-1            | 
frontend-1            | Failed to parse source map from '/app/node_modules/parse5/dist/common/html.js.map' file: Error: ENOENT: no such file or directory, open '/app/node_modules/parse5/dist/common/html.js.map'
frontend-1            | 
frontend-1            | Failed to parse source map from '/app/node_modules/parse5/dist/common/token.js.map' file: Error: ENOENT: no such file or directory, open '/app/node_modules/parse5/dist/common/token.js.map'
frontend-1            | 
frontend-1            | Failed to parse source map from '/app/node_modules/parse5/dist/common/unicode.js.map' file: Error: ENOENT: no such file or directory, open '/app/node_modules/parse5/dist/common/unicode.js.map'
frontend-1            | 
frontend-1            | Failed to parse source map from '/app/node_modules/parse5/dist/index.js.map' file: Error: ENOENT: no such file or directory, open '/app/node_modules/parse5/dist/index.js.map'
frontend-1            | 
frontend-1            | Failed to parse source map from '/app/node_modules/parse5/dist/parser/formatting-element-list.js.map' file: Error: ENOENT: no such file or directory, open '/app/node_modules/parse5/dist/parser/formatting-element-list.js.map'
frontend-1            | 
frontend-1            | Failed to parse source map from '/app/node_modules/parse5/dist/parser/index.js.map' file: Error: ENOENT: no such file or directory, open '/app/node_modules/parse5/dist/parser/index.js.map'
frontend-1            | 
frontend-1            | Failed to parse source map from '/app/node_modules/parse5/dist/parser/open-element-stack.js.map' file: Error: ENOENT: no such file or directory, open '/app/node_modules/parse5/dist/parser/open-element-stack.js.map'
frontend-1            | 
frontend-1            | Failed to parse source map from '/app/node_modules/parse5/dist/serializer/index.js.map' file: Error: ENOENT: no such file or directory, open '/app/node_modules/parse5/dist/serializer/index.js.map'
frontend-1            | 
frontend-1            | Failed to parse source map from '/app/node_modules/parse5/dist/tokenizer/index.js.map' file: Error: ENOENT: no such file or directory, open '/app/node_modules/parse5/dist/tokenizer/index.js.map'
frontend-1            | 
frontend-1            | Failed to parse source map from '/app/node_modules/parse5/dist/tokenizer/preprocessor.js.map' file: Error: ENOENT: no such file or directory, open '/app/node_modules/parse5/dist/tokenizer/preprocessor.js.map'
frontend-1            | 
frontend-1            | Failed to parse source map from '/app/node_modules/parse5/dist/tree-adapters/default.js.map' file: Error: ENOENT: no such file or directory, open '/app/node_modules/parse5/dist/tree-adapters/default.js.map'
frontend-1            | 
frontend-1            | Search for the keywords to learn more about each warning.
frontend-1            | To ignore, add // eslint-disable-next-line to the line before.
frontend-1            | 
frontend-1            | WARNING in ./node_modules/parse5/dist/common/doctype.js
frontend-1            | Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
frontend-1            | Failed to parse source map from '/app/node_modules/parse5/dist/common/doctype.js.map' file: Error: ENOENT: no such file or directory, open '/app/node_modules/parse5/dist/common/doctype.js.map'
frontend-1            | 
frontend-1            | WARNING in ./node_modules/parse5/dist/common/error-codes.js
frontend-1            | Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
frontend-1            | Failed to parse source map from '/app/node_modules/parse5/dist/common/error-codes.js.map' file: Error: ENOENT: no such file or directory, open '/app/node_modules/parse5/dist/common/error-codes.js.map'
frontend-1            | 
frontend-1            | WARNING in ./node_modules/parse5/dist/common/foreign-content.js
frontend-1            | Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
frontend-1            | Failed to parse source map from '/app/node_modules/parse5/dist/common/foreign-content.js.map' file: Error: ENOENT: no such file or directory, open '/app/node_modules/parse5/dist/common/foreign-content.js.map'
frontend-1            | 
frontend-1            | WARNING in ./node_modules/parse5/dist/common/html.js
frontend-1            | Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
frontend-1            | Failed to parse source map from '/app/node_modules/parse5/dist/common/html.js.map' file: Error: ENOENT: no such file or directory, open '/app/node_modules/parse5/dist/common/html.js.map'
frontend-1            | 
frontend-1            | WARNING in ./node_modules/parse5/dist/common/token.js
frontend-1            | Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
frontend-1            | Failed to parse source map from '/app/node_modules/parse5/dist/common/token.js.map' file: Error: ENOENT: no such file or directory, open '/app/node_modules/parse5/dist/common/token.js.map'
frontend-1            | 
frontend-1            | WARNING in ./node_modules/parse5/dist/common/unicode.js
frontend-1            | Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
frontend-1            | Failed to parse source map from '/app/node_modules/parse5/dist/common/unicode.js.map' file: Error: ENOENT: no such file or directory, open '/app/node_modules/parse5/dist/common/unicode.js.map'
frontend-1            | 
frontend-1            | WARNING in ./node_modules/parse5/dist/index.js
frontend-1            | Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
frontend-1            | Failed to parse source map from '/app/node_modules/parse5/dist/index.js.map' file: Error: ENOENT: no such file or directory, open '/app/node_modules/parse5/dist/index.js.map'
frontend-1            | 
frontend-1            | WARNING in ./node_modules/parse5/dist/parser/formatting-element-list.js
frontend-1            | Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
frontend-1            | Failed to parse source map from '/app/node_modules/parse5/dist/parser/formatting-element-list.js.map' file: Error: ENOENT: no such file or directory, open '/app/node_modules/parse5/dist/parser/formatting-element-list.js.map'
frontend-1            | 
frontend-1            | WARNING in ./node_modules/parse5/dist/parser/index.js
frontend-1            | Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
frontend-1            | Failed to parse source map from '/app/node_modules/parse5/dist/parser/index.js.map' file: Error: ENOENT: no such file or directory, open '/app/node_modules/parse5/dist/parser/index.js.map'
frontend-1            | 
frontend-1            | WARNING in ./node_modules/parse5/dist/parser/open-element-stack.js
frontend-1            | Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
frontend-1            | Failed to parse source map from '/app/node_modules/parse5/dist/parser/open-element-stack.js.map' file: Error: ENOENT: no such file or directory, open '/app/node_modules/parse5/dist/parser/open-element-stack.js.map'
frontend-1            | 
frontend-1            | WARNING in ./node_modules/parse5/dist/serializer/index.js
frontend-1            | Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
frontend-1            | Failed to parse source map from '/app/node_modules/parse5/dist/serializer/index.js.map' file: Error: ENOENT: no such file or directory, open '/app/node_modules/parse5/dist/serializer/index.js.map'
frontend-1            | 
frontend-1            | WARNING in ./node_modules/parse5/dist/tokenizer/index.js
frontend-1            | Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
frontend-1            | Failed to parse source map from '/app/node_modules/parse5/dist/tokenizer/index.js.map' file: Error: ENOENT: no such file or directory, open '/app/node_modules/parse5/dist/tokenizer/index.js.map'
frontend-1            | 
frontend-1            | WARNING in ./node_modules/parse5/dist/tokenizer/preprocessor.js
frontend-1            | Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
frontend-1            | Failed to parse source map from '/app/node_modules/parse5/dist/tokenizer/preprocessor.js.map' file: Error: ENOENT: no such file or directory, open '/app/node_modules/parse5/dist/tokenizer/preprocessor.js.map'
frontend-1            | 
frontend-1            | WARNING in ./node_modules/parse5/dist/tree-adapters/default.js
frontend-1            | Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
frontend-1            | Failed to parse source map from '/app/node_modules/parse5/dist/tree-adapters/default.js.map' file: Error: ENOENT: no such file or directory, open '/app/node_modules/parse5/dist/tree-adapters/default.js.map'
frontend-1            | 
frontend-1            | webpack compiled with 14 warnings
frontend-1            | No issues found.

Why?

I don't want to use sourceMap, I don't use sourceMaps, I just want the warnings gone to get my current work through deployment.

tried setting GENERATE_SOURCEMAP=false as some suggested, but it did not change anything.

@jimrandomh
Copy link

Duplicate of: rehypejs/rehype-raw#28

This appears to have been previously fixed, but no release has been made since the fix was merged. Anyone want to make a 7.1.3?

@justinfagnani
Copy link

I get a flood of these errors from my dev server if I open dev tools. If there's a fix merged already, it'd be awesome to get that release. @RReverser I see you've published before, could you push a new release?

@43081j
Copy link
Collaborator

43081j commented Jul 6, 2024

can we also maybe just turn sourcemaps off in the published package? @fb55 what do you think? i seem to remember you suggesting that too

@fb55
Copy link
Collaborator

fb55 commented Jul 6, 2024

I believe we merged a PR that disabled source maps already? We haven't published a new release with it yet.

As an alternative, I have recently started moving my packages to https://github.com/isaacs/tshy, which opts to add the source files to the package.

@justinfagnani
Copy link

Publishing the source maps would be best, imo. Is it as simple for this project as turning it on in the tsconfig?

@43081j
Copy link
Collaborator

43081j commented Jul 7, 2024

I think so yes. We seem to run TSC twice to create a cjs and esm build. So we should be able to just turn on source maps for both in the tsconfig

@fb55
Copy link
Collaborator

fb55 commented Jul 7, 2024

Source maps only work with source files being added to the published package, so that would be the one additional change required. But I don't see a reason not to do so.

@43081j
Copy link
Collaborator

43081j commented Jul 7, 2024

The package is already pretty chunky. Id prefer to avoid bloating it any more

Do we definitely need the source files alongside? I thought source maps were enough to tell the browser the info it needs

@fb55
Copy link
Collaborator

fb55 commented Jul 7, 2024

We had only the source maps without source files before, this led to #831

For my own modules, my previous solution was to have the source root of the source maps point at the source files on GitHub (see my comment in the issue linked above). That is difficult to do with the TS monorepo setup, but we could work around it via separate builds.

@43081j
Copy link
Collaborator

43081j commented Jul 7, 2024

wasn't #831 just us forgetting to package up .map files? the error was that the referenced file didn't exist (the map file). nothing there seems to suggest anything to do with typescript

i guess im missing something

@justinfagnani
Copy link

Yes, you just need the source map. The inlineSources config option will let you embed the original source in the source map files: https://www.typescriptlang.org/tsconfig/#inlineSources

@fb55
Copy link
Collaborator

fb55 commented Jul 7, 2024

The inlineSources config option will let you embed the original source in the source map files

Source maps have to be generated for each variant, so if download size is a concern, adding the source files to the package would avoid duplication in the source maps.

edit: Thanks for pointing this out, didn't know about the flag!

@fb55
Copy link
Collaborator

fb55 commented Jul 7, 2024

the error was that the referenced file didn't exist (the map file). nothing there seems to suggest anything to do with typescript

True – source maps weren't included in the first place as their source files wouldn't be resolved.

@43081j
Copy link
Collaborator

43081j commented Jul 7, 2024

If we had packaged up the map files, the sources would be resolved, no? You don't literally need the source files afaik, like Justin mentioned

We just forgot to package up the map files

@fb55
Copy link
Collaborator

fb55 commented Jul 7, 2024

We just forgot to package up the map files

We didn't set the inlineSources before, which made the source maps refer to source files that were not shipped with the package — this led to another resolution error. The "fix" was to add source maps to npm's ignores, without realising that they were referenced in the source files themselves (leading to this issue).

@nielskrijger
Copy link

I'm wondering if something still needs to be done on this issue or is it just waiting for a release?

@m-conti
Copy link

m-conti commented Sep 2, 2024

Hello is it a way to mute this warning until a release ?

EDIT:
I've write a script inside the postinstall to avoid the issue:
// package.json

{
  "scripts": {
    ...,
    "postinstall": "find node_modules/parse5 -type f -name '*.js' -exec sed -i '' '/^\\/\\/\\# sourceMappingURL=.*/d' {} +"
  },
}

@43081j
Copy link
Collaborator

43081j commented Sep 2, 2024

@fb55 do we just need to disable source maps or something here?

Would be super helpful if you can make the call and push the new version out

@nielskrijger
Copy link

We get a long list of warnings each time parse5 is loaded, so this issue is a bit of a pain.

The workaround @m-conti works on Mac but didn't work on our CI/CD running linux. Sadly my bash skills are pretty poor so instead wrote the following postinstall script to remove the source mapping:

/**
 * This script is used to remove source mapping directives in the parse5 library.
 * See also: https://github.com/inikulin/parse5/issues/1194
 */

const fs = require('fs')
const path = require('path')

/**
 * Remove source mapping directives from the given file.
 */
function removeSourceMapping(filePath) {
  const data = fs.readFileSync(filePath, 'utf8')
  const result = data.replace(/^\/\/# sourceMappingURL=.*$/gm, '')
  fs.writeFileSync(filePath, result, 'utf8')
}

/**
 * Remove source mapping from all files in the given directory.
 */
function removeSourceMappingFromDir(dir) {
  fs.readdirSync(dir).forEach((file) => {
    const fullPath = path.join(dir, file)
    if (fs.statSync(fullPath).isDirectory()) {
      removeSourceMappingFromDir(fullPath)
    } else if (fullPath.endsWith('.js') || fullPath.endsWith('.ts')) {
      removeSourceMapping(fullPath)
    }
  })
}

removeSourceMappingFromDir(path.join(__dirname, '..', 'node_modules', 'parse5'))

@43081j
Copy link
Collaborator

43081j commented Oct 10, 2024

Once the new version gets published soon, source maps will be disabled and this error should go away

If we want to re-enable them some day, we can then do it in another pr and ensure nothing is missing etc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants