I added NextjsSite to my stack, `yarn build` works...
# help
j
I added NextjsSite to my stack,
yarn build
works fine when run in the nextjs app's folder. When I try to build my stack though, I'm getting an error
Copy code
Error: There was a problem building the "testapp" NextjsSite.
    at NextjsSite.buildApp (/Users/jedrzej/Workspace/testapp/packages/sst/node_modules/@serverless-stack/resources/src/NextjsSite.ts:600:13)
    at new NextjsSite (/Users/jedrzej/Workspace/testapp/packages/sst/node_modules/@serverless-stack/resources/src/NextjsSite.ts:148:16)
...
I can see output from the next.js being built, there are no errors in there, the output is the same output I see when I build the app manually. Is there a way to get more information about what went wrong? I tried adding some console.logs in
/Users/jedrzej/Workspace/testapp/packages/sst/node_modules/@serverless-stack/resources/src/NextjsSite.ts
to see what the original error caught in there was, but for some reason it doesn't have any effect, as if it was cached by nodejs or sth...
f
Hey @Jędrzej Kuryło, can you try add logging to
@serverless-stack/resources/dist/NextjsSite.ts
?
j
will give it a try, cool, wasn't aware of the dist folder, I'm still pretty new to this 😇
@Frank does this mean anything to you?
I ran the node command manually, maybe this will give more details
still no errors. but for some reason
next build
returns
0
, while `````` returns
1
f
hmm.. Which version of Next.js r u using?
j
Next.js v12.0.7
f
Can u give
v11.1.4
a try (latest v11)? Just to rule out it’s the version issue.
j
sure
again,
next build
gives
0
, but
node ...
gives 1. But the output of both commands is different, got some warnings in the latter, will fix them first and see if it helped
Copy code
info  - Creating an optimized production build...
(node:18146) [DEP_WEBPACK_CHUNK_HAS_ENTRY_MODULE] DeprecationWarning: Chunk.hasEntryModule: Use new ChunkGraph API
(Use `node --trace-deprecation ...` to show where the warning was created)
warn  - Compiled with warnings

./node_modules/next/dist/server/load-components.js
Critical dependency: the request of a dependency is an expression

./node_modules/next/dist/server/load-components.js
Critical dependency: the request of a dependency is an expression

./node_modules/next/dist/server/load-components.js
Critical dependency: the request of a dependency is an expression

./node_modules/next/dist/server/require.js
Critical dependency: the request of a dependency is an expression

./node_modules/next/dist/server/require.js
Critical dependency: the request of a dependency is an expression

./node_modules/next/dist/server/require.js
Critical dependency: the request of a dependency is an expression
those are extra lines I see in the output when I build with sst, it's not there when i do
next build
btw, @Frank, when I add NextjsSite to my stack, will it use
next build
and
next start
to build and run the app? or does it use the build/start scripts in
package.json
?
d
will it use 
next build
 and 
next start
 to build and run the app?
next build only
, in production there is no "run" persay, its a series of infrastructure and moving parts that should, more or less, mimic
npm start
.
j
FYI, the part that was breaking the build, was trying to pass some env variables to Next.js app
Copy code
const webpack = require('webpack');
const dotenv = require('dotenv');

dotenv.config();

const apiKey = JSON.stringify(process.env.SHOPIFY_API_KEY);

/** @type {import('next').NextConfig} */
module.exports = {
  webpack: config => {
    const env = { API_KEY: apiKey };
    config.plugins.push(new webpack.DefinePlugin(env));

    return config;
  },
  reactStrictMode: true,
};
if I remove the
webpack
property, it builds just fine with
sst build
f
@Jędrzej Kuryło can I see how you are passing
SHOPIFY_API_KEY
in?
j
dotenv loads the
.env
file, and the file is just
SHOPIFY_API_KEY=<my-key>
It might be unrelated to sst and I got it all to work already
f
Oh nice! 👍