Parcel: Parcel with source maps enabled cannot import LiveScript

Created on 13 Dec 2018  ยท  22Comments  ยท  Source: parcel-bundler/parcel

๐Ÿ› bug report

Parcel with source maps enabled cannot import LiveScript

๐ŸŽ› Configuration (.babelrc, package.json, cli command)

{
  "name": "livescript-parcel",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "parcel build index.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "livescript": "^1.6.0",
    "parcel-bundler": "^1.10.3"
  }
}

๐Ÿค” Expected Behavior

import livescript from 'livescript' should work

๐Ÿ˜ฏ Current Behavior

 > parcel build index.js

โš ๏ธ  Could not load existing sourcemap of "node_modules/livescript/lib/index.js".
๐Ÿšจ  livescript-parcel/node_modules/livescript/lib/index.js:69:43: Expecting Unicode escape sequence \uXXXX (69:43)
  67 |         if ((ref$ = options.map) === 'linked' || ref$ === 'debug') {
  68 |           mapPath = path.basename(outputFilename) + ".map";
> 69 |           result.code += "\n + mapPath + "\n";
     |                                           ^
  70 |         } else {
  71 |           result.code += "\n//# sourceMappingURL=data:application/json;base64," + bufferFrom(result.map.toString()).toString('base64') + "\n";
  72 |         }

It appears that parcel is incorrectly interpreting the file as a source map.

        if ((ref$ = options.map) === 'linked' || ref$ === 'debug') {
          mapPath = path.basename(outputFilename) + ".map";
          result.code += "\n//# sourceMappingURL=" + mapPath + "\n";
        } else {
          result.code += "\n//# sourceMappingURL=data:application/json;base64," + bufferFrom(result.map.toString()).toString('base64') + "\n";
        }

๐Ÿ’ป Code Sample

https://github.com/raine/livescript-parcel

Bug Confirmed Bug Source Maps

Most helpful comment

Two fixes :

  • either remove \n from strings in the package sources (node_modules/paper/dist/paper-full.js in my case)
  • or disable source-maps: parcel index.html --no-source-maps

Is there a better solution?

All 22 comments

Maybe could - as proposed by @mischnic check for the beginning & end of this.content matching SOURCEMAP_RE and only then load source map. I think this regex matches it and Parcel was able to bundle the sources with it, tests seemed fine.

// either start or end with SOURCEMAP_RE
// full regex:  /^\s*\/\/\s*[@#]\s*sourceMappingURL\s*=\s*([^\s]+)|\/\/\s*[@#]\s*sourceMappingURL\s*=\s*([^\s]+)\s*$/;
^\s*SOURCEMAP_RE|SOURCEMAP_RE\s*$

Means - sourcemaps can't be referenced somewhere in the middle of the bundle. How do people feel about that?

Means - sourcemaps can't be referenced somewhere in the middle of the bundle. How do people feel about that?

That is not supported, so it should be fine. The spec (Google Document (!)) says:

The generated code may include a line at the end of the source, with the following form:

//# sourceMappingURL=<url>

So adding \s*$ to the current regex should be enough.

Ok, that sounds good enough. Would you like to open a PR? If busy, I can do too.

Ok, that sounds good enough. Would you like to open a PR? If busy, I can do too.

Go ahead!

Same issue with TypeScript.

The line in dependency:

sourceMap && (css += "\n/*# sourceMappingURL=data:application/json;base64," + btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap)))) + " */");

have transformed to

sourceMap && (css += "\n + btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap)))) + " */");

Part of the string and the quote was cut

Can we get a release cut with this fix before 2.0? We aren't able to compile with source maps which is making debugging difficult. I'd like to avoid forking and cherry-picking the fix

This just bit me when importing vuejs-datepicker into my project. A temporary workaround was to use parcel with --no-source-maps, but I'm looking forward to the proper solution.

Seems to me it could at least have been fixed in the current release. We just tried to move our project to parcel and were greeted to this purposely not-fixed error.

Is there a way to disable sourcemaps for a single module?

@eranimo No

I'm running to the same issue using "onfido-sdk-ui". Tried with
"parcel": "^1.12.4",
and
"parcel": "^2.0.0-alpha.3.2",

erver running at http://localhost:1234
โš ๏ธ Could not load existing sourcemap of "../../../node_modules/onfido-sdk-ui/lib/index.js".
๐Ÿšจ /Users/genechan....../node_modules/onfido-sdk-ui/lib/index.js:1:8498: Unexpected token (1:8498)

I am having this issue as well with the video-react package

Could not load existing sourcemap of "../../core/src/components/VideoPlayer/video-react.es.js

Same issue with paper.js:

Arthur:3my4v Arthur$ parcel index.html 
Server running at http://localhost:1234 
โš ๏ธ  Could not load existing sourcemap of "node_modules/paper/dist/paper-full.js".
โ ‹ Building css-loader.js...Browserslist: caniuse-lite is outdated. Please run next command `yarn upgrade`
Browserslist: caniuse-lite is outdated. Please run next command `yarn upgrade`
๐Ÿšจ  /Users/Arthur/Desktop/3my4v/node_modules/paper/dist/paper-full.js:17211:12: Unterminated string constant (17211:12)
  17209 |           }
  17210 |           if (/^(inline|both)$/.test(sourceMaps)) {
> 17211 |               code += "\n
        |                      ^
  17212 |                       + self.btoa(unescape(encodeURIComponent(
  17213 |                           JSON.stringify(map))));
  17214 |           }
โš ๏ธ  Could not load existing sourcemap of "node_modules/paper/dist/paper-full.js".

Two fixes :

  • either remove \n from strings in the package sources (node_modules/paper/dist/paper-full.js in my case)
  • or disable source-maps: parcel index.html --no-source-maps

Is there a better solution?

Is there going to be a fix for this in a pre 2.0 release? I'd like to NOT disable sourcemaps since they are providing us with some useful context in our logs when errors occur in our application.

If you don't have plans for a fix, then I need to start making plans as to whether or not to upgrade our parcel bundler to 2.0. I know you are working on documentation still for 2.0 but I just assume that upgrade path is not going to be simple.

Ran into this issue with an imported React component that was bundled with webpack. Especially unfortunate because I had to use webpack to bundle that component in the first place because of https://github.com/parcel-bundler/parcel/issues/3305 On the plus side, the --no-source-maps is an acceptable workaround for me.

(I frigging love Parcel btw, I wish I could use it all the time for everything!)

I add --no-source-maps and the problem is gone.

But it's needed for development.

@medmin does it work in Parcel 2?

I think we fixed this.

@DeMoorJasper I think I've encountered the same problem. Update to Parcel 2 worked for me. The code sample (https://github.com/raine/livescript-parcel) runs for me without build errors, when I use Parcel 2.

๐Ÿ› Bug Report

Parcel with source maps enabled cannot import ckeditor5 Editor

๐ŸŽ› Configuration (.babelrc, package.json, cli command)

{
  "name": "parcel-ckeditor",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "parcel build index.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@ckeditor/ckeditor5-build-classic": "^20.0.0",
    "@ckeditor/ckeditor5-react": "^2.1.0",
    "parcel-bundler": "^1.12.4",
    "react": "^16.13.1",
    "react-dom": "^16.13.1"
  }
}

๐Ÿค” Expected Behavior

import ClassicEditor from '@ckeditor/ckeditor5-build-classic' should work

๐Ÿ˜ฏ Current Behavior

> parcel build index.js

โš ๏ธ  Could not load existing sourcemap of "node_modules/@ckeditor/ckeditor5-build-classic/build/ckeditor.js".
๐Ÿšจ  parcel-ckeditor/node_modules/@ckeditor/ckeditor5-build-classic/build/ckeditor.js:5:6589: Unexpected token (5:6589)
  3 |  * For licensing, see LICENSE.md.
  4 |  */
> 5 | !function(t){const e=t.en=t.en||{};e.dictionary=Object.assign(e.dictionary||{},{"%0 o ...

๐Ÿ’ Possible Solution

Use Parcel 2

npm install -D parcel@next

๐ŸŒ Environment

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 1.12.4 |
| Node | 14.4.0 |
| npm | 6.14.5 |

@chhch please open a seperate bug report for that, that doesn't actually seem like a sourcemap bug though

i'm sorry to say @DeMoorJasper but this is not fixed in 1.x versions. adding the --no-source-maps is a hack not a proper way to use it. can you please provide the PR or commit it for this fix?

Was this page helpful?
0 / 5 - 0 ratings