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

bug in a browser:Uncaught ReferenceError: process is not defined. #3222

Closed
masx200 opened this issue Jun 3, 2021 · 8 comments
Closed

bug in a browser:Uncaught ReferenceError: process is not defined. #3222

masx200 opened this issue Jun 3, 2021 · 8 comments

Comments

@masx200
Copy link

masx200 commented Jun 3, 2021

bug in a browser:

process.emitWarning(

Uncaught ReferenceError: process is not defined

You should use "console.warn" when running in a browser.

@masx200 masx200 changed the title Uncaught ReferenceError: process is not defined bug in a browser:Uncaught ReferenceError: process is not defined. Jun 3, 2021
@joshgoebel
Copy link
Member

joshgoebel commented Jun 3, 2021

Can you provide a reproducible example or JSFiddle? That code should never even be run in a web browser (and doesn't even exist in our web builds)... it's solely for Node if you import the files improperly (would double extensions)... Those .js.js files should never be referenced directly.

What setup are you using to bundle? And what does the code where you import us look like?

@masx200
Copy link
Author

masx200 commented Jun 3, 2021

import hljs from "highlight.js/lib/core.js";


import javascript from "highlight.js/lib/languages/javascript.js";

export default hljs;
hljs.registerLanguage("javascript", javascript);

@joshgoebel

@joshgoebel
Copy link
Member

joshgoebel commented Jun 3, 2021

It should be imported with out any extension (so the dynamic exports can do their thing), which is what the warning says.

import javascript from "highlight.js/lib/languages/javascript";

Perhaps we should have introduced a build-time error instead.

@masx200
Copy link
Author

masx200 commented Jun 3, 2021

"d:\Documents\github\markdown-reader\node_modules\highlight.js\lib\languages\javascript.js.js"

function emitWarning() {
    if (!emitWarning.warned) {
      emitWarning.warned = true;
      process.emitWarning(
        'Using file extension in specifier is deprecated, use "highlight.js/lib/languages/javascript" instead of "highlight.js/lib/languages/javascript.js"',
        'DeprecationWarning'
      );
    }
  }
  emitWarning();
    module.exports = require('./javascript.js');

@masx200
Copy link
Author

masx200 commented Jun 3, 2021

I should be able to use highlight.js in the browser correctly with webpack 5.

@masx200
Copy link
Author

masx200 commented Jun 3, 2021

I upgraded highlight.js from 10.7.2 to 11.0, and then it crashed.
@joshgoebel

@joshgoebel
Copy link
Member

joshgoebel commented Jun 3, 2021

As I said, you need to remove the .js from your import:

import javascript from "highlight.js/lib/languages/javascript"; // NO .js extension

Languages are now always imported without an extension in version 11.

joshgoebel added a commit to joshgoebel/highlight.js that referenced this issue Jun 4, 2021
Technically (with a build system) this code could end up in the
browser, so we should use only APIs available in both browser and
node.js.

Resolves highlightjs#3222.
joshgoebel added a commit that referenced this issue Jun 4, 2021
Technically (with a build system) this code could end up in the
browser, so we should use only APIs available in both browser and
node.js.

Resolves #3222.
@joshgoebel
Copy link
Member

Resolved with release of 11.0.1.

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

2 participants