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

Parcel with source maps enabled cannot import LiveScript #2408

Closed
raine opened this issue Dec 13, 2018 · 23 comments
Closed

Parcel with source maps enabled cannot import LiveScript #2408

raine opened this issue Dec 13, 2018 · 23 comments

Comments

@raine
Copy link

raine commented Dec 13, 2018

🐛 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

@mischnic
Copy link
Member

mischnic commented Dec 13, 2018

I guess the source map detection should check if it's at the end of the file (as in: there are no non-whitespace characters after the comment)

const SOURCEMAP_RE = /\/\/\s*[@#]\s*sourceMappingURL\s*=\s*([^\s]+)/;

async loadSourceMap() {
// Get original sourcemap if there is any
let match = this.contents.match(SOURCEMAP_RE);
if (match) {
this.contents = this.contents.replace(SOURCEMAP_RE, '');
let url = match[1];

@lustoykov
Copy link
Contributor

lustoykov commented Dec 17, 2018

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?

@mischnic
Copy link
Member

mischnic commented Dec 17, 2018

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.

@lustoykov
Copy link
Contributor

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

@mischnic
Copy link
Member

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

Go ahead!

@Ni55aN
Copy link

Ni55aN commented Jul 31, 2019

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

@beeeth
Copy link

beeeth commented Sep 27, 2019

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

@impworks
Copy link

impworks commented Oct 1, 2019

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.

@isra17
Copy link

isra17 commented Oct 9, 2019

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.

@eranimo
Copy link

eranimo commented Dec 28, 2019

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

@mischnic
Copy link
Member

@eranimo No

@genechan
Copy link

genechan commented Feb 4, 2020

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)

dbecherdialpad added a commit to dbecherdialpad/parcel that referenced this issue Mar 9, 2020
@gward35
Copy link

gward35 commented Mar 17, 2020

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

@arthursw
Copy link

arthursw commented Mar 21, 2020

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".

@arthursw
Copy link

arthursw commented Mar 21, 2020

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?

taneliang pushed a commit to nusmodifications/nusbusiness that referenced this issue Mar 30, 2020
@dinoc
Copy link

dinoc commented Apr 21, 2020

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.

@izaleu
Copy link

izaleu commented Apr 26, 2020

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 #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!)

@medmin
Copy link

medmin commented Jul 9, 2020

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

But it's needed for development.

@DeMoorJasper
Copy link
Member

@medmin does it work in Parcel 2?

I think we fixed this.

@chhch
Copy link

chhch commented Jul 17, 2020

@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

@DeMoorJasper
Copy link
Member

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

@woss
Copy link

woss commented Sep 8, 2020

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?

@Maker-Mark
Copy link

This is still an issue with 1.x.

ap-- added a commit to Bayer-Group/pavo that referenced this issue Sep 17, 2021
As always frontend dev is convoluted. parcel v1 doesn't play nicely
with vue: parcel-bundler/parcel#2408 so
we would need to disable source maps. But that'll slow down dev, so
we migrate to v2. That comes with its own baggage, but hopefully
it'll be the lesser of the two evils.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.