parcel-bundler / parcel

The zero configuration build tool for the web. 📦🚀
https://parceljs.org
MIT License
43.5k stars 2.27k forks source link

Error: Cannot find module 'https//....' #4005

Closed techsin closed 4 years ago

techsin commented 4 years ago

🐛 bug report

Parcel 2 tries to build online urls not only links to file on drive. It starts with html template that has script tags. Some script tags point to public cdn urls. Which are NOT meant to be bundled.

🎛 Configuration (.babelrc, package.json, cli command)

package.json

{
  "dev": "parcel serve --port 8080 src/index.pug",
}

.babelrc

{
  "plugins": [
    "@babel/plugin-transform-modules-commonjs",
    [
      "@babel/plugin-proposal-class-properties",
      {
        "loose": true
      }
    ]
  ],
  "presets": [
    "@babel/preset-env",
    "@babel/preset-react"
  ]
}

🤔 Expected Behavior

Not give an error

😯 Current Behavior

Error Error: Cannot find module 'https//....'

Software Version(s)
Parcel 2.0.0-alpha.3.2
Node 10.11
npm 6.4.1
Operating System 10.15.2
DeMoorJasper commented 4 years ago

Could you give a bit more context?

This should not happen

Sent with GitHawk

techsin commented 4 years ago

what do I tell?

my package.json has following packages

    "parcel": "^1.12.4",
    "parcel-plugin-envkey": "^1.1.0",
    "parcel-plugin-graphql-raw": "^1.0.3",
techsin commented 4 years ago

index.pug looks like this

index.pug

...
  script(src="//domain.com/global/all.js" type="text/javascript")
mischnic commented 4 years ago

Error: Cannot find module 'https//....'

For some reason, the : is missing, and so Parcel doesn't recognize this as an url (and excludes it). https://github.com/parcel-bundler/parcel/blob/v2/packages/core/parcel-bundler/src/utils/is-url.js

Are you sure this is valid pug syntax?

techsin commented 4 years ago

I tried it with without https as well, just script(src="//domain.com/global/all.js"

DeMoorJasper commented 4 years ago

I think you need to use: script(src="https://domain.com/global/all.js" as parcel will detect that as a valid link

techsin commented 4 years ago

//url.... is a valid url, at least common practice. it means use http if page is under http and use https if page is https.

techsin commented 4 years ago

https://stackoverflow.com/questions/4978235/absolute-urls-omitting-the-protocol-scheme-in-order-to-preserve-the-one-of-the

mischnic commented 4 years ago

Yes, //domain.com/xyz is a valid url in html, but https//domain.com/xyz isn't.

> require("pug").compile("script(src='//domain.com/global/all.js')")()
'<script src="//domain.com/global/all.js"></script>'
> require("is-url")("//domain.com/x")
true
> require("is-url")("https//domain.com/x")
false

The question is: where does that https come from

techsin commented 4 years ago

It already was //domain.com/xyz than i tried adding https.. anyways i tried again

Error: Cannot find module '//domain.com/global/all.js'

npx parcel --version 
2.0.0-alpha.3.2
techsin commented 4 years ago

if i change it to proper https://domain.com

i get this error

import {Transformer} from '@parcel/plugin';
       ^

SyntaxError: Unexpected token {
    at new Script (vm.js:79:7)
    at createScript (vm.js:251:10)
    at Object.runInThisContext (vm.js:303:10)
    at Module._compile (internal/modules/cjs/loader.js:657:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
DeMoorJasper commented 4 years ago

@techsin could you give us a reproducible repo with that last issue?

Can't really tell what the issue is from that stack, I think it has to do with one of the plugins you use.

techsin commented 4 years ago

Ok I'll try