FredKSchott / snowpack

ESM-powered frontend build tool. Instant, lightweight, unbundled development. ✌️
https://www.snowpack.dev
MIT License
19.48k stars 922 forks source link

[optimize] The entry point "$WORK_DIR\\build\\build\\index.js" cannot be marked as external error #2318

Closed rhkdgns95 closed 3 years ago

rhkdgns95 commented 3 years ago

Problem

CLI

KIMHT@KIM MINGW64 ~/Downloads/project/isos (master)
$ yarn build
yarn run v1.22.10
warning package.json: No license field
$ snowpack build
[snowpack] ! building source files...
[snowpack] ✔ build complete [4.51s]
[snowpack] ! building dependencies...
[snowpack] ✔ dependencies ready! [55.08s]
[snowpack] ! verifying build...
[snowpack] ✔ verification complete [0.06s]
[snowpack] ! writing build to disk...
[snowpack] ! optimizing build...
 > error: The entry point "C:\\Users\\KIMHT\\Downloads\\project\\isos\\build\\build\\index.js" cannot be marked as external

1 error
[snowpack] Build failed with 1 error:
error: The entry point "C:\\Users\\KIMHT\\Downloads\\project\\isos\\build\\build\\index.js" cannot be marked as external
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

KIMHT@KIM MINGW64 ~/Downloads/project/isos (master)

package.json

{
  "devDependencies": {
    "@babel/plugin-transform-react-jsx": "^7.12.12",
    "@babel/preset-env": "^7.12.11",
    "@babel/preset-react": "^7.12.10",
    "@babel/preset-typescript": "^7.12.7",
    "@snowpack/plugin-babel": "^2.1.5",
    "@snowpack/plugin-react-refresh": "^2.3.9",
    "@types/react": "^17.0.0",
    "@types/react-dom": "^17.0.0",
    "@types/react-router-dom": "^5.1.6",
    "@types/styled-components": "^5.1.7",
    "parcel-bundler": "^1.12.4",
    "rimraf": "^3.0.2",
    "snowpack": "^3.0.10",
    "typescript": "^4.1.3",
    "vercel": "^21.0.1"
  },
  "dependencies": {
    "@ant-design/icons": "^4.3.0",
    "@nivo/bar": "^0.67.0",
    "@nivo/bump": "^0.67.0",
    "@nivo/calendar": "^0.67.0",
    "@nivo/circle-packing": "^0.67.0",
    "@nivo/core": "^0.67.0",
    "@nivo/line": "^0.67.0",
    "@nivo/pie": "^0.67.0",
    "ag-grid-community": "^24.1.0",
    "ag-grid-react": "^24.1.1",
    "antd": "^4.9.4",
    "dayjs": "^1.9.8",
    "rc-picker": "^2.5.0",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-router-dom": "^5.2.0",
    "react-to-print": "^2.12.2",
    "recoil": "^0.1.2",
    "styled-components": "^5.2.1"
  },
  "scripts": {
    "cleanup": "rimraf build",
    "start:parcel": "parcel public/index.html --port 3000 --open",
    "build:parcel": "parcel build public/index.parcel.html -d build --no-source-maps",
    "start": "snowpack dev --reload",
    "build": "snowpack build"
  }
}

snowpack.config.js

// Snowpack Configuration File
// See all supported options: https://www.snowpack.dev/#configuration

/** @type {import("snowpack").SnowpackUserConfig } */
module.exports = {
  mount: {
    public: "/",
    src: "/build",
  },
  plugins: ["@snowpack/plugin-react-refresh", "@snowpack/plugin-babel"],
  devOptions: {
    port: 3000,
    open: "chrome",
  },
  packageOptions: {
    polyfillNode: true,
    namedExports: ["react-to-print"],
    knownEntrypoints: ["react/jsx-runtime"],
    // external: ["build"]
  },
  exclude: [
    "**/*.otf"
  ],
  routes: [{ src: ".*", dest: "index.html", match: "routes" }],
  // TODO : optimize 3.0 부터 에러발생
  optimize: {
    manifest: true,
    preload: true,
    splitting: true,
    treeshake: true,
    minify: true,
    bundle: true,
    target: "es2018",
  },
};
FredKSchott commented 3 years ago

Interesting, thanks for filing this. We have this line in our optimize.ts file that could be causing trouble:

    external: Array.from(new Set(allFiles.map((f) => '*' + path.extname(f)))).filter(
      (ext) => ext !== '*.js' && ext !== '*.mjs' && ext !== '*.css',
    ),

I think it's missing a check for a file without an extension, which would result in "*" being marked external (which would mean every file in your project). That's obviously not expected :)

I went ahead and fixed that issue in 0fc858cf. I'm still not 100% sure that that's the issue, but there's a good chance that it is.

Do you have any files in your build that don't hav an extension? If you do not, then it would be great to know what the result of external is (the value that we're passing to external and also the value of allFiles) if you feel comfortable adding console.log messages and then re-running.

FredKSchott commented 3 years ago

Closing this issue because we reserve issues for prioritized, triaged work. In the future, please create a Discussion!

goosechaser commented 3 years ago

Same issue here. Clean project using the Svelte configuration (https://www.snowpack.dev/tutorials/svelte). Config:

    optimize: {
        bundle: true,
        minify: true,
        target: 'es2018'
    },

Error:

[snowpack] ! building source files...
[snowpack] ✔ build complete [0.16s]
[snowpack] ! building dependencies...
[snowpack] ✔ dependencies ready! [0.28s]
[snowpack] ! verifying build...
[snowpack] ✔ verification complete [0.00s]
[snowpack] ! writing build to disk...
[snowpack] ! optimizing build...
 > error: The entry point "/snowpack/build/index.js" cannot be marked as external

 > error: The entry point "/snowpack/build/index.css" cannot be marked as external

2 errors
[snowpack] Build failed with 2 errors:
error: The entry point "/snowpack/build/index.js" cannot be marked as external
error: The entry point "/snowpack/build/index.css" cannot be marked as external
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ build: `snowpack build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /.npm/_logs/2021-01-17T17_55_11_811Z-debug.log

It looks like the issue is LICENSE in the root folder. No extension, so it fails.

rhkdgns95 commented 3 years ago

Interesting, thanks for filing this. We have this line in our optimize.ts file that could be causing trouble:

    external: Array.from(new Set(allFiles.map((f) => '*' + path.extname(f)))).filter(
      (ext) => ext !== '*.js' && ext !== '*.mjs' && ext !== '*.css',
    ),

I think it's missing a check for a file without an extension, which would result in "*" being marked external (which would mean every file in your project). That's obviously not expected :)

I went ahead and fixed that issue in 0fc858c. I'm still not 100% sure that that's the issue, but there's a good chance that it is.

Do you have any files in your build that don't hav an extension? If you do not, then it would be great to know what the result of external is (the value that we're passing to external and also the value of allFiles) if you feel comfortable adding console.log messages and then re-running.

FredKSchott commented 3 years ago

We just need to do a new Snowpack release of the fix. Or, you could check out this repo locally and run directly from the repo until that release goes out

rhkdgns95 commented 3 years ago

Thank you for your quick response request. @FredKSchott

aspeddro commented 3 years ago

Updated to the latest version 3.0.11, the error persists.

optimize: {
    bundle: true,
    minify: false,
    target: 'es2018'
},
amok commented 3 years ago

I confirm that 3.0.11 does not fix the issue. Did a little investigation and it looks like version 3.0.11 just doesn't contain the fix https://github.com/snowpackjs/snowpack/blob/snowpack%403.0.11/snowpack/src/build/optimize.ts#L402. I hope https://github.com/snowpackjs/snowpack/commit/0fc858cf0e5ff65be57337985be63d68fa94035b will get to the next release.