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/transformer-js: Non-static access of an import or require. This causes tree shaking to be disabled for the resolved module #7109

Closed
antimatter96 opened this issue Oct 16, 2021 · 4 comments · Fixed by #8136

Comments

@antimatter96
Copy link

antimatter96 commented Oct 16, 2021

🐛 bug report

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

.parcelrc

{
  "extends": "@parcel/config-default"
}

package.json

{
  "name": "calc",
  "version": "0.0.1",
  "scripts": {
    "dev": "parcel",
    "build": "rm -rf ./../dist && parcel build --dist-dir ./../dist --log-level verbose"
  },
  "source": "src/index.html",
  "dependencies": {
    "parcel": "^2.0.0",
    "posthtml": "^0.16.5",
    "posthtml-include": "^1.7.2"
  },
  "license": "MIT"
}

🤔 Expected Behavior

No warnings

😯 Current Behavior

Warnings

parcel/transformer-js: Non-static access of an `import` or `require`. This causes tree shaking to be disabled for
the resolved module.
  ...../js/main.js:x:y
  > x |   let w = new Week();
  >   |                ^^^^

💁 Possible Solution

🔦 Context

💻 Code Sample

directory

root
 ┣ src
 ┃ ┣ js
 ┃ ┃ ┣ main.js
 ┃ ┃ ┣ week.js
 ┃ ┣ index.html
 ┃ ┗ style.css
 ┣ .parcelrc
 ┣ package.json
 ┗ yarn.lock

index.html

<!DOCTYPE html>
<html lang="en">

<head>
  <link rel="stylesheet" href="./style.css">
  <title>Progress</title>
</head>

<body>
  <script type="module" src="./js/main.js"></script>
</body>

</html>

js/main.js

import { Week } from "./week";
let w = new Week();

js/week.js

export class Week {
  constructor(input) {}
}

🌍 Your Environment

Software Version(s)
Parcel 2.0.0
Node v14.17.6
npm/Yarn 1.22.10
Operating System macOS Big Sur 11.4
@antimatter96 antimatter96 changed the title @parcel/transformer-js: Non-static access of an import or require. This causes tree shaking to be disabled for the resolved module. @parcel/transformer-js: Non-static access of an import or require. This causes tree shaking to be disabled for the resolved module.` Oct 16, 2021
@antimatter96 antimatter96 changed the title @parcel/transformer-js: Non-static access of an import or require. This causes tree shaking to be disabled for the resolved module.` @parcel/transformer-js: Non-static access of an import or require. This causes tree shaking to be disabled for the resolved module Oct 16, 2021
@DexterHaxxor
Copy link

Still not fixed, when will we get proper warnings?

@ebrensi
Copy link

ebrensi commented Mar 15, 2022

Is there a way to disable that particular warning? I find that lots of this warning are getting in the way of reading other information.

EDIT: Setting --log-level info suppresses the warning.

@tcstory
Copy link

tcstory commented Mar 21, 2022

still meet the problem, the tree shaking is disabled , the version of parcel is 2.3.2,

@jteppinette
Copy link

Why does this disable tree shaking?

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.

6 participants