nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨

Home Page:https://nodejs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

error: no template named 'remove_cv_t' in namespace 'std'; did you mean 'remove_cv'?

AirWSW opened this issue · comments

  • Version:v16.0.0
  • Platform:Darwin 20.3.0 arm64 (Apple Silicon)

What steps will reproduce the bug?

When building node-sass@5.0.0, the error occurred.

How often does it reproduce? Is there a required condition?

ALWAYS, arm64 (Apple Silicon)

What is the expected behavior?

NO error

What do you see instead?

/Users/***/Library/Caches/node-gyp/16.0.0/include/node/v8-internal.h:452:38: error: no template named 'remove_cv_t' in namespace 'std'; did you mean 'remove_cv'?
            !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
                                ~~~~~^~~~~~~~~~~
                                     remove_cv
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/type_traits:697:50: note: 'remove_cv' declared here
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_cv
                                                 ^
1 error generated.
make: *** [Release/obj.target/binding/src/binding.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/***/*/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (node:events:365:28)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
gyp ERR! System Darwin 20.3.0
gyp ERR! command "/opt/homebrew/Cellar/node/16.0.0/bin/node" "/Users/***/*/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /Users/***/*/node_modules/node-sass
gyp ERR! node -v v16.0.0

Additional information

Here is the ref link:

V8_INLINE void PerformCastCheck(T* data) {
CastCheck<std::is_base_of<Data, T>::value &&
!std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
}

When replacing remove_cv_t with remove_cv, it seems to work well.

I think it's a bug of node-sass.

Refs: microsoft/node-pty#441 (comment) and microsoft/node-pty#433

I think Node.js v16 isn't supported by node-sass@5.0.0 from the release note.

There is also an ongoing issue sass/node-sass#3077 in order to support Node.js v16.

If you need to use node-sass now, I'd suggest to revert to the latest Node v14 LTS.

Thanks!

The latest Node v14 LTS has not supported Apple Silicon natively, while v16 is the best choice for me. Fortunately, I found that sass/node-sass#3091 is trying to upgrade the cpp standard to 14, thereby fixing the macOS building errors.

I'm downgrading to 15.14 following : https://michael.codes/posts/nodejs_apple_silicon/
Hopefully it will work 🤞

EDIT: it worked, but my macbook air m1 got really hot during the node build (>10mins)

Ok managed to "solve" the issue.
The issue seems to be tied to the cpp compiler specified by the dependency's bindings.gyp when building native addons on Apple Silicon.

TLDR (though may have unexpected consequences)

yarn install -std=c++17

This arises, because remove_cv_t is only supported since C++14 (ref). For whatever reason, Node 16, when paired with cpp on Apple Silicon does not have the ability to properly resolve the incorrect remove_cv_t reference if cpp is given a language flag that is less than -std=c++14 (i.e. -std=c++11 in the case ofnode-sass.)

Obviously the best option would be to submit PRs to bump the cpp flags of dependencies. However for dependencies deep in the tree, this can take sometimes months or years bubble up to the top-level dependency. Brute forcing the cpp flags seems to be the only option until the environment shakes out.

Not sure what the equivalent npm command should be, but if someone who is more familiar with npm can post the correct flag, that would be great.

Thanks to @stevecondylios for the solution, from microsoft/node-pty#441 (comment) for the solution

RUN CXXFLAGS="--std=c++14" npm install

It is work for me

FYI, I'm experiencing this issue on an Intel based Mac also. Downgrading to node 14 fixed the issue though.

commented

On m1 mac, using Node.js 16.7, with a project that has node-sass, the following worked:

CXXFLAGS="--std=c++14" yarn

Thank you @litobear

CXXFLAGS="--std=c++14" npm install worked for me as well on Intel Mac

Can confirm CXXFLAGS="--std=c++14" npm install works on Mac with Node v17.4.0 as well

Also works for WSL2

node -v
v16.13.1

npm -v
8.5.1


CXXFLAGS="--std=c++14" npm rebuild node-sass

Works
CXXFLAGS="--std=c++14" npm install
M1 node 17!

yarn install -std=c++17 worked for me, Mac Mini M1. Node 17.8.0

May be i haven't fully understood it, the solution that is proposed in the thread with npm to set CXXFLAGS="--std=c++14" is a workaround, right ? But what about the permanent fix for this ? We can't set this flag while running the npm ci in pipelines. Please suggest a permanent fix for this.

#38367 (comment)

^^^ comment explains the situation pretty well.

I'm happy to pair with you on a fix if you want to send me a DM.

I saw the comment, actually my use case is i need to upgrade from node 14 to node 16 and by doing so it started showing me this error. Mine is an ionic angular application using npm. From some research it was also saying that the issue is related to node-sass incompatibility with the node-16.
Mine issue is resolved by running following :-
CXXFLAGS="--std=c++14" npm install
but do i need to set this flag everytime installing package and what about the ci pipeline - how will it handle npm install ?
Let me know how can i connect with you for DM , my gmail id is dheeraj053@gmail.com

I have tried Node v16~18 on Manjaro x86_64, and Node v16+CXXFLAGS="--std=c++14" works finally. I don't want to try more combinations any more for its installation has spent me lots of time.

There is an issue and a pull request on support node-sass+Node v18, and it seems it is almost ready for merging to mainline. Hope it can support new version Node.JS better.

The successful try:

  • OS: Manjaro x86_64
  • Node: v16.15.1
  • yarn: v1.22.19
  • gcc: 12.1.0 (from Manjaro package repository)
  • C++ compilation flags: --std=c++14

CXXFLAGS="--std=c++17" yarn install
worked for me - node 16