question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] `rimrafSafe(): …/node_modules/object-assign/index.js` outside of `buildOptions.out` when `optimize.bundle` is on

See original GitHub issue

Bug Report Quick Checklist

  • I am on the latest version of Snowpack & all plugins.
  • I use package manager npm (Fill in: npm, yarn, pnpm, etc).
  • I run Snowpack on OS Mac (Fill in: Windows, Mac, Linux, etc).
  • I run Snowpack on Node.js v14 & v16

Describe the bug

My project depends on single-spa-react. When optimize.bundle in the Snowpack config is turned on, importing this module produces the following during the build:

[17:06:41] [snowpack] rimrafSafe(): /Users/emccarthy/Developer/snowpack-repro/react-snowpack/node_modules/object-assign/index.js outside of buildOptions.out /Users/emccarthy/Developer/snowpack-repro/react-snowpack/build

To Reproduce

  1. npm init snowpack-app --template @snowpack/app-template-react
  2. npm install
  3. npm install single-spa-react
  4. Edit snowpack.config.js to set optimize.bundle to true
  5. Edit index.jsx to add import 'single-spa-react'
  6. npm run build
  7. See error!

Expected behavior

No error. 😄

Anything else?

The single-spa-react package does a require("react") in a top-level try/catch block. I think this might be triggering esbuild’s importing of the module and bypassing Snowpack’s import, evidenced by the fact that the import is pulling from node_modules and not _snowpack/pkg.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:8
  • Comments:18

github_iconTop GitHub Comments

9reactions
adieuadieucommented, Jun 8, 2021

I have the same-looking issue when using the framer-motion library (or, more specifically its @emotion/memoize dependency). Node v14.2.0.

Marcos-MBP:new-dir marco$ npm run build

> @ build /Users/marco/src/temp/framer-snowpack-repro/new-dir
> snowpack build

[16:53:07] [snowpack] ! building files...
[16:53:07] [snowpack] ✔ files built. [0.07s]
[16:53:07] [snowpack] ! building dependencies...
[16:53:10] [@snowpack/plugin-typescript] Command completed.
[16:53:10] [snowpack] ✔ dependencies built. [3.09s]
[16:53:10] [snowpack] ! writing to disk...
[16:53:10] [snowpack] ✔ write complete. [0.02s]
[16:53:10] [snowpack] ! optimizing build...
[16:53:10] [snowpack] rimrafSafe(): /Users/marco/src/temp/framer-snowpack-repro/new-dir/node_modules/@emotion/memoize/dist/memoize.browser.cjs.js outside of buildOptions.out /Users/marco/src/temp/framer-snowpack-repro/new-dir/build
[16:53:10] [snowpack] Error: rimrafSafe(): /Users/marco/src/temp/framer-snowpack-repro/new-dir/node_modules/@emotion/memoize/dist/memoize.browser.cjs.js outside of buildOptions.out /Users/marco/src/temp/framer-snowpack-repro/new-dir/build
    at Object.deleteFromBuildSafe (/Users/marco/src/temp/framer-snowpack-repro/new-dir/node_modules/snowpack/lib/index.js:34081:15)
    at Object.runBuiltInOptimize (/Users/marco/src/temp/framer-snowpack-repro/new-dir/node_modules/snowpack/lib/index.js:152260:24)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async Object.optimize$1 [as optimize] (/Users/marco/src/temp/framer-snowpack-repro/new-dir/node_modules/snowpack/lib/index.js:183387:9)
    at async build (/Users/marco/src/temp/framer-snowpack-repro/new-dir/node_modules/snowpack/lib/index.js:183419:5)
    at async Object.command (/Users/marco/src/temp/framer-snowpack-repro/new-dir/node_modules/snowpack/lib/index.js:183436:9)
    at async cli (/Users/marco/src/temp/framer-snowpack-repro/new-dir/node_modules/snowpack/lib/index.js:183748:9)

To Reproduce

  1. npx create-snowpack-app new-dir --template @snowpack/app-template-react-typescript
  2. cd new-dir && npm install framer-motion
  3. Edit snowpack.config.js to set optimize.bundle to true
  4. Edit src/App.tsx and add import { motion } from 'framer-motion'
  5. Edit src/App.tsx and add <motion.div /> on line 19ish to the React Component
  6. npm run build
  7. See error!
4reactions
funkytekcommented, Jun 10, 2021

Same issue as @adieuadieu with @emotion/memoize - any insights on this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found