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: "node_compat = true" is being ignored [Node builtin module import while Node compatibility is disabled] #1150

Closed
rauleite opened this issue May 30, 2022 · 1 comment · Fixed by #1153 or #1131
Assignees
Labels
bug Something that isn't working

Comments

@rauleite
Copy link

What version of Wrangler are you using?

2.0.7

What operating system are you using?

Linux

Describe the Bug

Error:
[plugin: checkForNodeBuiltins] Detected a Node builtin module import while Node compatibility is disabled.
Add node_compat = true to your wrangler.toml file to enable Node compatibility.

But, I already had add the node_compat on wrangler.toml:

name = "api"
compatibility_date = "2022-05-16"
account_id = "1b5b99f85df2ff3830dfec7cb7cee2d9"
workers_dev = true

# Seems it's not working
node_compat = true

# --- STAGING ---
[env.staging]
  main = "dist/bundle.js"
  [dev]
    # ip = "192.168.0.103"
    # @default `8787`

[env.staging.build]
  command = "pnpm run build"  

The file that throws the error:

src/index.ts

import puppeteer from 'puppeteer-extra'
import StealthPlugin from 'puppeteer-extra-plugin-stealth'

/**
Line with that throws the error:
PS. works only if comment this line
*/
puppeteer.use(StealthPlugin())

addEventListener("fetch", (event) => {
  //@ts-ignore
  event.respondWith(handleRequest(event.request));
});

//@ts-ignore
async function handleRequest(request) {
  return new Response("Hello worker!", {
    headers: { "content-type": "text/plain" },
  });
}

I'm using with webpack:

package.json

"build": "webpack"
"dev": "wrangler dev -e staging --local"

webpack.config.cjs

module.exports = {
  target: "webworker",
  mode: "development",
  devtool: 'cheap-module-source-map',
  entry: './src/index.ts',
  /*
    It throws with or without 'externals' and 'externalsPresets'
  */
  externals: [
    nodeExternals()
  ],
  externalsPresets: {
    node: true
  },
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        use: 'ts-loader',
        exclude: /node_modules/,
      },
    ],
  },

  resolve: {
    extensions: ['.tsx', '.ts', '.js'],
  },
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist'),
  }
}

My repo with minimal code for error reproduction:
https://github.com/rauleite/issue

  • Node: 17.9.0
  • pnpm: 7.1.6
@rauleite rauleite added the bug Something that isn't working label May 30, 2022
@petebacondarwin
Copy link
Contributor

Thanks for this excellent issue report and reproduction. I was able to use it to reproduce the problem locally.
It is indeed a bug, since we are not correctly inheriting the node_compat value into named environments.

@petebacondarwin petebacondarwin moved this to Untriaged in workers-sdk May 31, 2022
@petebacondarwin petebacondarwin moved this from Untriaged to In Progress in workers-sdk May 31, 2022
@petebacondarwin petebacondarwin self-assigned this May 31, 2022
petebacondarwin added a commit to petebacondarwin/wrangler2 that referenced this issue May 31, 2022
@petebacondarwin petebacondarwin moved this from In Progress to Approved in workers-sdk May 31, 2022
Repository owner moved this from Approved to Done in workers-sdk May 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that isn't working
Projects
None yet
2 participants